class documentation

class FieldPath(list[FieldKey]): (source)

Constructor: FieldPath(base)

View In Hierarchy

Ordered path of FieldKey components.

Field paths are convenience objects that can be converted to masks and can be combined with other paths or masks using +.

Example

Construct a path and build a mask:

path = FieldPath(["spec", "max_size_bytes"])
mask = path.to_mask()
assert mask.marshal() == "spec.max_size_bytes"
Parameters
baseOptional iterable of FieldKey or strings used to build the path. Strings are converted to FieldKey and validated.
Raises
ValueErrorIf base is not iterable or contains invalid element types.
Class Method unmarshal Parse a single-path mask string into a FieldPath.
Method __add__ Combine with another path or attach a mask at the end.
Method __eq__ Return True when another object is an equal path.
Method __iadd__ Append path components from an iterable.
Method __init__ Create a field path from keys or strings.
Method __repr__ Return a debug representation of the path.
Method copy Return a shallow copy of the path.
Method is_prefix_of Return True if this path is a strict prefix of another path.
Method marshal Serialize the path as a mask string.
Method matches_reset_mask Return True if the path is covered by a reset mask.
Method matches_reset_mask_final Return True if the path matches and terminates a reset mask.
Method matches_select_mask Return True if the path is covered by a select mask.
Method matches_select_mask_inner Return match status and whether the match is inner or final.
Method parent Return the parent path or None when at root.
Method to_mask Convert the path into a mask with a single leaf.
Static Method _matches_reset_mask Undocumented
Static Method _matches_select_mask Undocumented
@classmethod
def unmarshal(cls, s: str) -> FieldPath | None: (source)

Parse a single-path mask string into a FieldPath.

Parameters
s:strMarshaled mask string.
Returns
FieldPath | NoneA FieldPath or None when the mask is empty.
Raises
ErrorWhen the mask contains wildcards or multiple paths.
@overload
def __add__(self, value: Iterable[FieldKey | str]) -> FieldPath:
@overload
def __add__(self, value: Mask) -> Mask:
(source)

Combine with another path or attach a mask at the end.

Parameters
other:Iterable[FieldKey | str] | MaskIterable of keys to append or a Mask to attach.
Returns
FieldPath | MaskA new FieldPath or Mask.
def __eq__(self, value: object) -> bool: (source)

Return True when another object is an equal path.

Parameters
value:objectObject to compare.
Returns
boolTrue if equal, otherwise False.
def __iadd__(self, value: Iterable[FieldKey | str]) -> FieldPath: (source)

Append path components from an iterable.

Parameters
value:Iterable[FieldKey | str]Iterable of FieldKey or strings to append.
Returns
FieldPathThis path instance.
Raises
ValueErrorIf an element is not a FieldKey or string.
@overload
def __init__(self):
@overload
def __init__(self, base: Iterable[FieldKey | str]):
(source)

Create a field path from keys or strings.

def __repr__(self) -> str: (source)

Return a debug representation of the path.

def copy(self) -> FieldPath: (source)

Return a shallow copy of the path.

Returns
FieldPathNew FieldPath instance.
def is_prefix_of(self, value: FieldPath) -> bool: (source)

Return True if this path is a strict prefix of another path.

Parameters
value:FieldPathPath to compare with.
Returns
boolTrue if this path is a strict prefix.
def marshal(self) -> str: (source)

Serialize the path as a mask string.

Returns
strMarshaled mask string.
def matches_reset_mask(self, mask: Mask | None) -> bool: (source)

Return True if the path is covered by a reset mask.

Parameters
mask:Mask | NoneMask to test against.
Returns
boolTrue if the path is matched, otherwise False.
def matches_reset_mask_final(self, mask: Mask | None) -> bool: (source)

Return True if the path matches and terminates a reset mask.

Parameters
mask:Mask | NoneMask to test against.
Returns
boolTrue if the path is matched and terminal.
def matches_select_mask(self, mask: Mask | None) -> bool: (source)

Return True if the path is covered by a select mask.

Parameters
mask:Mask | NoneMask to test against.
Returns
boolTrue if the path is matched, otherwise False.
def matches_select_mask_inner(self, mask: Mask | None) -> tuple[bool, bool]: (source)

Return match status and whether the match is inner or final.

Parameters
mask:Mask | NoneMask to test against.
Returns
tuple[bool, bool]Tuple of (has_match, is_inner).
def parent(self) -> FieldPath | None: (source)

Return the parent path or None when at root.

Returns
FieldPath | NoneParent path or None if this path is empty.
def to_mask(self) -> Mask: (source)

Convert the path into a mask with a single leaf.

Returns
MaskMask representing this path.
@staticmethod
def _matches_reset_mask(fp: FieldPath | list[FieldKey], mask: Mask | None) -> tuple[bool, bool]: (source)

Undocumented

@staticmethod
def _matches_select_mask(fp: FieldPath | list[FieldKey], mask: Mask | None) -> tuple[bool, bool]: (source)

Undocumented