Entry API
sweet_tea.entry.Entry
Bases: BaseModel
A registry entry containing information about a registered class.
Each entry represents a class that has been registered with the factory system, including metadata for filtering and instantiation.
model_dump() names the class class_def — the name an entry is constructed
with — and reports it as stored, so dumping a lazy entry yields None rather than
importing. A resolved entry dumps a live class, which no JSON encoder accepts, so
:class:~sweet_tea.registry_snapshot.RegistrySnapshot stays the serialisation
path for anything leaving the process.
Source code in sweet_tea/entry.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 71 72 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 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
class_def
property
The registered class, imported on first read if the entry is lazy.
Reading this is how a lazily registered entry becomes a real one, so existing code that introspects the registry keeps seeing a class rather than None:
matches = [entry.class_def for entry in Registry.entries() if ...]
Only this entry's own module is imported, so a filtered read resolves only what
it touched. Use :attr:is_lazy to check the state without importing anything.
Reading this does not make the entry look resolved. entries() returns a
copy of the registry's list, not of its entries, so this object may well be the
registry's own -- and a reader must not change what the registry reasons about.
The class is cached privately instead (see :attr:_resolved); the registry
becomes the resolved entry's author when it reconciles the module.
Returns:
| Type | Description |
|---|---|
type | None
|
The class, or None for an entry that is neither resolved nor resolvable. |
Raises:
| Type | Description |
|---|---|
SweetTeaError
|
When importing the module fails. Reading an attribute can therefore raise, which is the cost of keeping the old contract. |
identity
property
The four values that decide whether two registrations are duplicates.
Mirrors what Entry.__eq__ compares for eager entries. A lazy entry has no
class object yet, so it identifies its target by module:attribute instead
— which also means a lazy and an eager registration of one class do not
collapse into a single entry (see SWE-10).
is_lazy
property
Whether this entry still needs its module imported.
Deliberately reads the stored field rather than :attr:class_def, so asking
the question does not answer it by importing -- and so that a reader having
resolved this entry's class does not make it look registered (SWE-37).