ModelProperty
- class glotaran.model.property.ModelProperty(cls: type, name: str, property_type: type, doc: str, default: Any, allow_none: bool)[source]
Bases:
property
ModelProperty is an extension of the property decorator.
It adds convenience functions for meta programming model items.
Create a new model property.
- Parameters
cls (type) – The class the property is being attached to.
name (str) – The name of the property.
property_type (type) – The type of the property.
doc (str) – A documentation string of for the property.
default (Any) – The default value of the property.
allow_none (bool) – Whether the property is allowed to be None.
Attributes Summary
Check if the property is allowed to be None.
Check if the type is mapping.
Check if the subtype is parameter.
Check if the type is scalar.
Check if the type is a sequence.
Get the subscribed type.
Get the type of the property.
Methods Summary
Descriptor to change the deleter on a property.
Descriptor to change the getter on a property.
Fill a property with items from a model and parameters.
Format a value to string.
Replace parameter values with their full label.
Validate a value against a model and optionally against parameters.
Get a markdown representation of the property.
Descriptor to change the setter on a property.
Methods Documentation
- deleter()
Descriptor to change the deleter on a property.
- fdel
- fget
- fset
- getter()
Descriptor to change the getter on a property.
- property glotaran_allow_none: bool
Check if the property is allowed to be None.
- Returns
Whether the property is allowed to be None.
- Return type
- glotaran_fill(value: Any, model: Model, parameter: ParameterGroup) Any [source]
Fill a property with items from a model and parameters.
This replaces model item labels with the actual items and sets the parameter values.
- Parameters
value (Any) – The property value.
model (Model) – The model to fill in.
parameter (ParameterGroup) – The parameters to fill in.
- Returns
The filled value.
- Return type
Any
- glotaran_format_value(value: Any, all_parameters: ParameterGroup | None = None, initial_parameters: ParameterGroup | None = None) str [source]
Format a value to string.
- Parameters
value (Any) – The value to format.
all_parameters (ParameterGroup | None) – A parameter group containing the whole parameter set (used for expression lookup).
initial_parameters (ParameterGroup | None) – The initial parameter.
- Returns
The formatted value.
- Return type
- property glotaran_is_mapping_property: bool
Check if the type is mapping.
- Returns
Whether the type is a mapping.
- Return type
- property glotaran_is_parameter_property: bool
Check if the subtype is parameter.
- Returns
Whether the subtype is parameter.
- Return type
- property glotaran_is_scalar_property: bool
Check if the type is scalar.
Scalar means the type is neither a sequence nor a mapping.
- Returns
Whether the type is scalar.
- Return type
- property glotaran_is_sequence_property: bool
Check if the type is a sequence.
- Returns
Whether the type is a sequence.
- Return type
- property glotaran_property_subtype: type
Get the subscribed type.
If the type is scalar, the type itself will be returned. If the type is a mapping, the value type will be returned.
- Returns
The subscribed type.
- Return type
- property glotaran_property_type: type
Get the type of the property.
- Returns
The type of the property.
- Return type
- glotaran_replace_parameter_with_labels(value: Any) Any [source]
Replace parameter values with their full label.
A convenience function for serialization.
- Parameters
value (Any) – The value to replace.
- Returns
The value with parameters replaced by their labels.
- Return type
Any
- glotaran_validate(value: Any, model: Model, parameters: ParameterGroup = None) list[str] [source]
Validate a value against a model and optionally against parameters.
- Parameters
value (Any) – The value to validate.
model (Model) – The model to validate against.
parameters (ParameterGroup) – The parameters to validate against.
- Returns
A list of human readable list of messages of problems.
- Return type
- glotaran_value_as_markdown(value: Any, all_parameters: ParameterGroup | None = None, initial_parameters: ParameterGroup | None = None) MarkdownStr [source]
Get a markdown representation of the property.
- Parameters
value (Any) – The property value.
all_parameters (ParameterGroup | None) – A parameter group containing the whole parameter set (used for expression lookup).
initial_parameters (ParameterGroup | None) – The initial parameter.
- Returns
The property as markdown string.
- Return type
- setter()
Descriptor to change the setter on a property.