elasticai.creator.ir.base.ir_data#
Module Contents#
Classes#
Convenience class for creating new Ir data classes. |
Functions#
API#
- class elasticai.creator.ir.base.ir_data.IrData(data: dict[str, elasticai.creator.ir.base.attribute.Attribute])[source]#
Convenience class for creating new Ir data classes.
To create a new Ir data class, inherit from
IrDataand define your required fields. Supported field types areExamples:
We can define a new class
MyNewIrDatawith the two required fieldsnameandlengthlike this:from elasticai.creator.ir import IrData, SimpleRequiredField, RequiredField class MyNewIrData(IrData): name: SimpleRequiredField[str] = SimpleRequiredField() # <1> length: RequiredField[str, int] = RequiredField(str, int) # <2> d = MyNewIrData({'name': 'my name', 'length': '12'}) d.name = 'new name' # <3> d.length += 3 # <4>
We define a simple required field. Data will be stored as string and can be accessed as string.
Opposed to 1. this field will store data as a string but every read or write access will convert length to an integer. The constructor
strwill be called when writing a value to the field andintwill be called on read.'new name'will be stored as is insided’s data dictionary. 4'12'will be converted to12before adding3to it, the subsequent write operation will convert15to the string'15'again.
IMPORTANT: Currently we assume that calling the conversion functions for a field will not result in any side effects. IMPORTANT: While it is ok to extend the available field types by inheritance the type annotations still need to refer to one of the provided field types, because they need to be analyzed by the metaclass.
Initialization
- attributes: elasticai.creator.ir.base.attributes_descriptor.AttributesDescriptor#
‘AttributesDescriptor(…)’
- elasticai.creator.ir.base.ir_data.ir_data_class(cls) collections.abc.Callable[[dict[str, elasticai.creator.ir.base.attribute.Attribute]], elasticai.creator.ir.base.ir_data.IrData][source]#