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

fdel

fget

fset

glotaran_allow_none

Check if the property is allowed to be None.

glotaran_is_mapping_property

Check if the type is mapping.

glotaran_is_parameter_property

Check if the subtype is parameter.

glotaran_is_scalar_property

Check if the type is scalar.

glotaran_is_sequence_property

Check if the type is a sequence.

glotaran_property_subtype

Get the subscribed type.

glotaran_property_type

Get the type of the property.

Methods Summary

deleter

Descriptor to change the deleter on a property.

getter

Descriptor to change the getter on a property.

glotaran_fill

Fill a property with items from a model and parameters.

glotaran_format_value

Format a value to string.

glotaran_replace_parameter_with_labels

Replace parameter values with their full label.

glotaran_validate

Validate a value against a model and optionally against parameters.

glotaran_value_as_markdown

Get a markdown representation of the property.

setter

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

bool

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

str

property glotaran_is_mapping_property: bool

Check if the type is mapping.

Returns

Whether the type is a mapping.

Return type

bool

property glotaran_is_parameter_property: bool

Check if the subtype is parameter.

Returns

Whether the subtype is parameter.

Return type

bool

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

bool

property glotaran_is_sequence_property: bool

Check if the type is a sequence.

Returns

Whether the type is a sequence.

Return type

bool

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

type

property glotaran_property_type: type

Get the type of the property.

Returns

The type of the property.

Return type

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

list[str]

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

MarkdownStr

setter()

Descriptor to change the setter on a property.