modelity.loc
- class modelity.loc.Loc(*path: Any)
Bases:
SequenceA tuple-like type that stores location of the value (or error) in the model tree.
Examples:
>>> from modelity.loc import Loc >>> root = Loc("root") >>> nested = root + Loc("nested") >>> nested Loc('root', 'nested') >>> nested += Loc(0) >>> nested Loc('root', 'nested', 0) >>> str(nested) 'root.nested.0' >>> nested[0] 'root' >>> nested[-1] 0
- Parameters:
*args – The positional arguments composing location’s path.
- __abstractmethods__ = frozenset({})
- __add__(other)
- __getitem__(index)
- __orig_bases__ = (typing.Sequence,)
- __parameters__ = ()
- __slots__ = ('_data',)
- classmethod irrelevant() Loc
Return a special location value indicating that the exact location is irrelevant.
This is equivalent to
Loc("_")and is typically used in containers like sets or unordered structures, where the concept of position or path does not apply.For example, when comparing or storing elements where their precise placement is not semantically meaningful, this sentinel location can be used to fulfill API requirements without implying an actual location.
Added in version 0.17.0.
- is_parent_of(other: Loc) bool
Check if this location is parent (prefix) of given other location.
- Parameters:
other – The other location object.
- suffix_match(pattern: Loc) bool
Check if suffix of this location matches given pattern.
Examples:
>>> Loc("foo").suffix_match(Loc("foo")) True >>> Loc("foo").suffix_match(Loc("foo", "bar")) False >>> Loc("foo", "bar").suffix_match(Loc("foo", "bar")) True >>> Loc("foo", "bar").suffix_match(Loc("foo", "*")) True >>> Loc("foo", 3, "bar").suffix_match(Loc("foo", "*", "bar")) True >>> Loc("foo", 3, "bar").suffix_match(Loc("foo", "*", "baz")) False
Added in version 0.27.0.