confingy.utils.containers#
containers
#
Helpers for traversing the containers that can hold tracked or lazy objects.
container_children
#
container_children(
value: Any,
) -> list[tuple[str, Any]] | None
Return (path_suffix, child) pairs for a supported container.
Supported containers are lists, tuples (including namedtuples), dicts, sets,
frozensets, and dataclass instances. Path suffixes look like [0] for
sequences, ['key'] for dicts, .field for dataclasses, and {} for set
members, which have no stable position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
Any value. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, Any]] | None
|
The container's children in iteration order, or None if |
list[tuple[str, Any]] | None
|
supported container. |
Source code in src/confingy/utils/containers.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
rebuild_container
#
rebuild_container(
value: Any, new_children: list[Any]
) -> Any
Return a copy of a container with its children replaced.
The container type is preserved where possible, including list and dict
subclasses such as OrderedDict and defaultdict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
A container supported by container_children. |
required |
new_children
|
list[Any]
|
The new children, in the order returned by
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
A new container of the same type as |
Source code in src/confingy/utils/containers.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
same_structure
#
same_structure(a: Any, b: Any) -> bool
Check whether two values are identical, or containers of identical values.
Containers are compared recursively by type, keys, and child identity. Leaf values are compared by identity only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
Any
|
The first value. |
required |
b
|
Any
|
The second value. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if |
bool
|
whose children are recursively the same. |
Source code in src/confingy/utils/containers.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |