ValueOptional

class dsviper.ValueOptional(type_optional, initial_value)

Bases: Value

A value of type optional<element_type>.

Or use Value.create(type_optional [, initial_value]).

This constructor builds a new container over the same elements, so only a mutation inside an element shows through.

static cast(value: Value | _OutputValues) → ValueOptional

Return value as an optional, or raise if it is not one.

clear() → None

Clear the container.

copy() → ValueOptional

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.

get(default: _InputValues | None = None, *, encoded: Literal[True] = True) → _OutputValues

Return the wrapped value or return default if given; otherwise raise.

Where ValueMap.get answers None for a missing key, an empty optional with no default raises.

encoded=False returns a Value rather than a native object.

hash() → int

Return the hash value.

is_nil() → bool

Return True if there is no value to unwrap.

representation() → str

Return the value written out: optional(<the value it holds>), or nil when it holds none.

type() → Type

Return the Type this value is an instance of.

type_code() → str

Return the code naming this kind of value, such as “int32”, “struct” or “vector”.

type_optional() → TypeOptional

Return the type optional<element_type>.

unwrap(*, encoded: Literal[True] = True) → _OutputValues

Return the wrapped value or raise.

encoded=False returns a Value rather than a native object.

wrap(value: _InputValues) → None

Store value in the optional, so it is no longer nil.