confingy.utils.types#
types
#
TrackedInstance
#
Bases: Protocol
Protocol for objects decorated with @track.
_tracked_info is private. Use
get_init_args to read the recorded constructor
arguments, and update or
map_fingy to change them.
Source code in src/confingy/utils/types.py
9 10 11 12 13 14 15 16 17 18 | |
is_lazy_type
#
is_lazy_type(obj: Any) -> bool
Check if an object is a Lazy type annotation.
Source code in src/confingy/utils/types.py
21 22 23 24 25 26 27 28 | |
is_lazy_instance
#
is_lazy_instance(obj: Any) -> TypeGuard[Lazy[Any]]
Check if an object is a Lazy instance.
Source code in src/confingy/utils/types.py
31 32 33 34 35 | |
is_tracked_instance
#
is_tracked_instance(obj: Any) -> TypeGuard[TrackedInstance]
Check if an object is a tracked instance (decorated with @track).
Tracked instances have a _tracked_info attribute that stores
the class name, module, and constructor arguments used to create them.
Source code in src/confingy/utils/types.py
38 39 40 41 42 43 44 45 | |
is_lazy_version_of
#
is_lazy_version_of(obj: Any, expected_type: type) -> bool
Check if an object is a Lazy version of a given type.
This compares classes by exact equality, so it does not match Lazies built
from track(expected_type), which creates a new subclass on every call. Use
is_fingy_of to match tracked and lazy objects of
a class or its subclasses.
Source code in src/confingy/utils/types.py
48 49 50 51 52 53 54 55 56 | |
is_nonlazy_subclass_of
#
is_nonlazy_subclass_of(
obj: Any, expected_supertype: type
) -> bool
Check if an object is a non-lazy subclass of a given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to check |
required |
expected_supertype
|
type
|
The expected supertype |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if obj is a subclass of expected_supertype and not lazy |
Source code in src/confingy/utils/types.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
is_all_lazy
#
is_all_lazy(obj: Any) -> bool
Check if an entire nested fingy is fully lazy.
This function recursively walks through a fingy and verifies that all tracked objects are Lazy instances (not already instantiated). This is useful to ensure a fingy can be safely mutated before instantiation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
The object to check. Can be a Lazy instance, dataclass, dict, list, or any other value. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all tracked objects in the structure are Lazy instances, |
bool
|
False if any tracked object has been instantiated. |
Examples:
@track
class Inner:
def __init__(self, value: int):
self.value = value
@track
class Outer:
def __init__(self, inner: Inner):
self.inner = inner
# All lazy - returns True
config = Outer.lazy(inner=Inner.lazy(value=1))
assert is_all_lazy(config)
# Contains instantiated object - returns False
config = Outer.lazy(inner=Inner(value=1)) # Inner is instantiated!
assert not is_all_lazy(config)
Source code in src/confingy/utils/types.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |