StructValue#

class tierkreis.core.values.StructValue(values: dict[str, TierkreisValue])[source]#

Bases: Generic[RowStruct], TierkreisValue

A composite structure of named fields.

Methods

from_object

Generate a StructValue from a python object using object member names as labels.

from_proto

Parses a tierkreis type from its protobuf representation.

from_proto_dict

from_python

Converts a python value to a tierkreis value.

from_python_union

Converts a python value to a tierkreis value, given a target python Union type.

from_tuple

Generate a StructValue from a tuple using tuple member indices as labels.

to_proto

to_proto_dict

to_python

Converts a tierkreis value to a python value given the desired python type.

to_python_union

Converts a tierkreis value to a python value given the desired union type.

try_autopython

Try to automatically convert to a python type without specifying the target types.

viz_str

String representation used in graph visualisation.

Attributes

values

classmethod from_object(value: Any, type_: Type | None = None) StructValue[source]#

Generate a StructValue from a python object using object member names as labels.

classmethod from_proto(value: Any) StructValue[source]#

Parses a tierkreis type from its protobuf representation.

classmethod from_python(value: Any, type_: Type | None = None) TierkreisValue#

Converts a python value to a tierkreis value. If type_ is not provided, it is inferred from the value.

classmethod from_python_union(value: Any, type_: UnionType) TierkreisValue#

Converts a python value to a tierkreis value, given a target python Union type.

classmethod from_tuple(tup: tuple[Any, ...]) StructValue[source]#

Generate a StructValue from a tuple using tuple member indices as labels.

to_python(type_: Type[T]) T#

Converts a tierkreis value to a python value given the desired python type.

When the specified python type is a type variable, the original TierkreisValue is returned unchanged. This allows us to write generic functions in which values of unknown type are passed on as they are.

to_python_union(type_: UnionType) Any#

Converts a tierkreis value to a python value given the desired union type.

try_autopython() Any | None#

Try to automatically convert to a python type without specifying the target types. Returns None if unsuccessful. Expected to be successful for “simple” or “leaf” types, that are not made up component types.

return:

Python value if successful, None if not.

rtype:

Optional[Any]

viz_str() str[source]#

String representation used in graph visualisation.