launch.frontend.entity module
Module for Entity class.
- class launch.frontend.entity.Entity[source]
Bases:
objectSingle item in the intermediate front_end representation.
- assert_entity_completely_parsed()[source]
Assert that all attributes and children of the entity were parsed.
This function is automatically called after the parse(entity, parser) function completed.
- get_attr(name: str, *, data_type: Type[TargetType], optional: bool, can_be_str: bool = True) TargetType | None[source]
- get_attr(name: str, *, data_type: Type[TargetType], can_be_str: bool = True) TargetType
- get_attr(name: str, *, optional: bool, can_be_str: bool = True) str | None
- get_attr(name: str, *, can_be_str: bool = True) str
Access an attribute of the entity.
By default, it will try to return it as an string. data_type is the expected type of the attribute. Type coercion or type checking is applied depending on the particular frontend.
See
launch.utilities.AllowedTypesTupleto see what types are allowed.data_type = None will result in yaml parsing of the attribute value as a string.
List[Entity] allows accessing a list of subentities with an specific name.
Check the documentation of each specific frontend implementation to see how a list of attributes or List[Entity] look like.
If optional is True and the attribute cannot be found, None will be returned instead of raising AttributeError.
- Parameters:
name – name of the attribute
data_type – type of the attribute to be read. Defaults to ‘str’
optional – when True, it doesn’t raise an error when the attribute is not found. It returns None instead. Defaults to False
- Raises:
AttributeError – Attribute not found. Only possible if optional is False
TypeError – Attribute found but it is not of the correct type. Only happens in frontend implementations that do type checking
ValueError – Attribute found but can’t be coerced to one of the specified types. Only happens in frontend implementations that do type coercion.