ValueStructure¶
- class dsviper.ValueStructure¶
Bases:
ValueA value of type struct. Seamless with a Python dict[str, object]. A field the dict leaves out takes its default.
Or use Value.create(type_structure [, initial_value]).
A field is written as an attribute - doc.name = value - or with set(field_name, value), and read either way. A name the struct does not declare is refused: as an attribute it raises AttributeError, Python’s protocol, which hasattr and getattr rely on; at() and set() with an unknown name raise ViperError. A field named like one of the methods every struct has - at, cast, copy, description, hash, representation, set, type, type_code, type_structure - is reached with at() and set() only: the attribute stays the method.
A container field reads as its handle, which a type checker sees as any value: ValueVector.cast(doc.tags) narrows it.
This constructor, given a value of its type, builds a deep copy of it: nothing it holds is shared.
- at(field_name, *, encoded: Literal[True] = True) _OutputValues¶
Return the value of the field called field_name.
encoded=False returns a Value rather than a native object.
- static cast(value: Value | _OutputValues) ValueStructure¶
Return value as a struct, or raise if it is not one.
- copy() ValueStructure¶
Return a deep copy.
- description(*, namespace: NameSpace | None = None) str¶
Return the value written out, then its type, as <value>:<type>.
namespace qualifies the type name; representation() gives the value alone.
- hash() int¶
Return the hash value.
- representation() str¶
Return the value written out: the fields between braces, comma separated.
- set(field_name: str, value: _InputValues) None¶
Write value into the field called field_name.
- type_code() str¶
Return the code naming this kind of value, such as “int32”, “struct” or “vector”.
- type_structure() TypeStructure¶
Return the type struct.