PathConst

class dsviper.PathConst

Bases: object

A finished Path: read or write the value it points at.

at() reads, set() and patch() assign. It also walks itself - parent, ancestors, components - reports whether it is regular, and encodes to a blob.

A PathConst and a Path with the same components compare equal: they carry the same path, and only the Path can still be extended.

Note: Not directly instantiable.

ancestors() → list[Path]

Return the list of ancestors.

at(target: Value, *, encoded: Literal[True] = True) → _OutputValues

Return what the path addresses inside target.

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

check_type(type: Type) → Type | None

Return the type the path reaches in type, or None through an any or a variant.

The type under an any or a variant is known only at runtime. Raise when the path does not fit type.

components() → list[PathComponent]

Return the list of components.

copy() → Path

Return a mutable Path holding the same components.

element_info() → PathElementInfo

Return the PathElementInfo.

encode(*, stream_codec_instancing: StreamCodecInstancing | None = None) → ValueBlob

Serialize the path into a blob.

Unrelated to the encoded= keyword of at(), which selects a native or a Value.

stream_codec_instancing chooses the codec; Codec.STREAM_BINARY is used when it is None - the same default Path.decode reads with.

entry_key_info() → PathEntryKeyInfo

Return the PathEntryKeyInfo.

from_component(index: int) → Path

Return a path from index.

has_prefix(path: PathConst) → bool

Return True if path is a prefix of this one.

is_applicable(value: Value) → bool

Check if the path is applicable to the value.

is_element_path() → bool

Return True if the path contains Element components.

is_entry_key_path() → bool

Return True if the path contains Entry components.

is_regular() → bool

Return True if the path holds neither an entry nor an element component.

set() takes a regular path, patch() one that is not.

is_root() → bool

Return True if self is the root.

last_component() → Path

Return the last component as a Path.

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

Return what the last component addresses, or raise on a root path.

An unwrap addresses void, which reads as None.

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

parent() → Path

Return the parent Path or raise if self is root.

patch(target: Value, value: _InputValues) → None

Replace, in target, a value that serves as its own key.

Such a value cannot be assigned in place, because changing it changes where it belongs: patch removes it and puts the new one back. Two shapes address one, and the path must be one of them - is_element_path() and is_entry_key_path() answer which, and anything else raises.

An element of a set, addressed by element(index): the element is the key. And the key of a map entry, addressed by entry(key) followed by index(0), where index(1) would address the value instead - that one raises here, since a value is assigned with set().

regularized() → Path

Return the path made regular.

An entry or an element component addresses a value that serves as its own key; the regular path addresses what it holds instead, so element(0) becomes [0] and entry(key).index(0) becomes [key]. A path already regular is answered unchanged.

representation() → str

Return a string representation.

set(target: Value, value: _InputValues) → None

Assign the value at this path in target.

The path must be regular, and not the root: an entry or an element component raises - patch() is the one that takes those.

to_component(index: int) → Path

Return a path to index (excluded).

write(*, stream_writing: StreamWriting) → None

Write the path into stream_writing.