modelrunner.model.parameters module
Infrastructure for managing classes with parameters.
One aim is to allow easy management of inheritance of parameters.
class representing a single parameter |
|
a parameter that can still be used normally but is deprecated |
|
a helper class that allows hiding parameters of the parent classes |
|
a mixin that manages the parameters of a class |
|
get a dictionary with all parameters of all registered classes |
- class DeprecatedParameter(name, default_value=None, cls=<class 'object'>, description='', choices=None, required=False, hidden=False, extra=<factory>)[source]
Bases:
Parameter
a parameter that can still be used normally but is deprecated
- Parameters:
- class HideParameter(name)[source]
Bases:
object
a helper class that allows hiding parameters of the parent classes
This parameter will still appear in the
parameters
dictionary, but it will typically not be visible to the user, e.g., when callingshow_parameters()
.- Parameters:
name (str) – The name of the parameter
- class Parameter(name, default_value=None, cls=<class 'object'>, description='', choices=None, required=False, hidden=False, extra=<factory>)[source]
Bases:
object
class representing a single parameter
- Parameters:
name (str) – The name of the parameter
default_value (Any) – The default value of the parameter
cls (type | Callable) – The type of the parameter, which is used for conversion. The conversion and parsing of values can be disabled by using the default class object.
description (str) – A string describing the impact of this parameter. This description appears in the parameter help.
choices (container) – A list or set of values that the parameter can take. Values (including the default value) that are not in this list will be rejected. Note that values are check after they have been converted by cls, so specifying cls is particularly important to convert command line parameters from strings.
required (bool) – Whether the parameter is required
hidden (bool) – Whether the parameter is hidden in the description summary
extra (dict) – Extra arguments that are stored with the parameter
- convert(value=NoValue, *, strict=True)[source]
converts a value into the correct type for this parameter. If value is not given, the default value is converted.
Note that this does not make a copy of the values, which could lead to unexpected effects where the default value is changed by an instance.
- Parameters:
value – The value to convert
strict (bool) – Flag indicating whether conversion to the type indicated by cls is enforced. If False, the original value is returned when conversion fails.
- Returns:
The converted value, which is of type self.cls
- default_value: Any = None
- class Parameterized(parameters=None, *, strict=True)[source]
Bases:
object
a mixin that manages the parameters of a class
initialize the parameters of the object
- Parameters:
parameters (dict) – A dictionary of parameters to change the defaults. The allowed parameters can be obtained from
get_parameters()
or displayed by callingshow_parameters()
.strict (bool) – Flag indicating whether parameters are strictly interpreted. If True, only parameters listed in parameters_default can be set and their type will be enforced.
- classmethod get_parameter_default(name)[source]
return the default value for the parameter with name
- Parameters:
name (str) – The parameter name
- classmethod get_parameters(include_hidden=False, include_deprecated=False, sort=True)[source]
return a dictionary of parameters that the class supports
- parameters_default: ParameterListType = []
parameters (with default values) of this subclass
- Type:
- show_parameters(description=False, sort=False, show_hidden=False, show_deprecated=False)[source]
show all parameters in human readable format
- Parameters:
description (bool) – Flag determining whether the parameter description is shown.
sort (bool) – Flag determining whether the parameters are sorted
show_hidden (bool) – Flag determining whether hidden parameters are shown
show_deprecated (bool) – Flag determining whether deprecated parameters are shown
- Return type:
None
All flags default to False.