elasticai.creator.ir.base.ir_data#

Module Contents#

Classes#

IrData

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 IrData and define your required fields. Supported field types are

Examples:

We can define a new class MyNewIrData with the two required fields name and length like 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>
  1. We define a simple required field. Data will be stored as string and can be accessed as string.

  2. 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 str will be called when writing a value to the field and int will be called on read.

  3. 'new name' will be stored as is inside d’s data dictionary. 4 '12' will be converted to 12 before adding 3 to it, the subsequent write operation will convert 15 to 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(…)’

get_missing_required_fields() dict[str, type][source]#
__repr__() str[source]#
__eq__(o: object) bool[source]#
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]#