|
18 | 18 | UnknownPlaceholderError, |
19 | 19 | WiringError, |
20 | 20 | ) |
21 | | -from apywire.threads import CompiledThreadSafeMixin |
| 21 | +from apywire.threads import ThreadSafeMixin |
22 | 22 | from apywire.wiring import ( |
23 | 23 | Spec, |
24 | 24 | SpecEntry, |
@@ -48,7 +48,7 @@ class _Constructor(Protocol): |
48 | 48 | def __call__(self, *args: object, **kwargs: object) -> object: ... |
49 | 49 |
|
50 | 50 |
|
51 | | -class WiringRuntime(WiringBase, CompiledThreadSafeMixin): |
| 51 | +class WiringRuntime(WiringBase, ThreadSafeMixin): |
52 | 52 | """Runtime container for wired objects. |
53 | 53 |
|
54 | 54 | This class handles the runtime resolution and instantiation of wired |
@@ -79,21 +79,23 @@ def __init__( |
79 | 79 | max_lock_attempts=max_lock_attempts, |
80 | 80 | lock_retry_sleep=lock_retry_sleep, |
81 | 81 | ) |
| 82 | + if self._thread_safe: |
| 83 | + self._init_thread_safety(max_lock_attempts, lock_retry_sleep) |
82 | 84 |
|
83 | 85 | def _init_thread_safety( |
84 | 86 | self, |
85 | 87 | max_lock_attempts: int = 10, |
86 | 88 | lock_retry_sleep: float = 0.01, |
87 | 89 | ) -> None: |
88 | 90 | """Initialize thread safety mixin.""" |
89 | | - CompiledThreadSafeMixin._init_thread_safety( |
| 91 | + ThreadSafeMixin._init_thread_safety( |
90 | 92 | self, max_lock_attempts, lock_retry_sleep |
91 | 93 | ) |
92 | 94 |
|
93 | 95 | def _get_resolving_stack(self) -> list[str]: |
94 | 96 | """Return the resolving stack for the current context.""" |
95 | 97 | if self._thread_safe: |
96 | | - return CompiledThreadSafeMixin._get_resolving_stack(self) |
| 98 | + return ThreadSafeMixin._get_resolving_stack(self) |
97 | 99 | return self._resolving_stack |
98 | 100 |
|
99 | 101 | def __getattr__(self, name: str) -> Accessor: |
@@ -124,13 +126,13 @@ def _instantiate_attr( |
124 | 126 | ) -> object: |
125 | 127 | """Instantiate an attribute using the configured strategy. |
126 | 128 |
|
127 | | - If thread_safe is True, uses the CompiledThreadSafeMixin implementation |
| 129 | + If thread_safe is True, uses the ThreadSafeMixin implementation |
128 | 130 | which handles optimistic locking and global fallback. |
129 | 131 | If thread_safe is False, uses a simple direct instantiation. |
130 | 132 | """ |
131 | 133 | if self._thread_safe: |
132 | 134 | # Use the mixin's implementation which handles locking |
133 | | - return CompiledThreadSafeMixin._instantiate_attr(self, name, maker) |
| 135 | + return ThreadSafeMixin._instantiate_attr(self, name, maker) |
134 | 136 |
|
135 | 137 | # Non-thread-safe path: simple check and set |
136 | 138 | if name in self._values: |
@@ -206,26 +208,31 @@ def _instantiate_impl(self, name: str) -> _RuntimeValue: |
206 | 208 | f"Unknown placeholder '{name}' referenced." |
207 | 209 | ) |
208 | 210 |
|
209 | | - module_name, class_name, factory_method, data = self._parsed[name] |
| 211 | + entry = self._parsed[name] |
210 | 212 |
|
211 | 213 | # Check for synthetic auto-promoted constant |
212 | | - if module_name == SYNTHETIC_CONST and class_name == "str": |
| 214 | + if ( |
| 215 | + entry.module_name == SYNTHETIC_CONST |
| 216 | + and entry.class_name == "str" |
| 217 | + ): |
213 | 218 | # This is an auto-promoted constant with string interpolation |
214 | | - value = self._format_string_constant(data, context=name) |
| 219 | + value = self._format_string_constant(entry.data, context=name) |
215 | 220 | self._values[name] = value |
216 | 221 | return value |
217 | 222 |
|
218 | | - module = importlib.import_module(module_name) |
219 | | - cls = cast(_Constructor, getattr(module, class_name)) |
| 223 | + module = importlib.import_module(entry.module_name) |
| 224 | + cls = cast(_Constructor, getattr(module, entry.class_name)) |
220 | 225 |
|
221 | 226 | # If a factory method is specified, get it from the class |
222 | | - if factory_method: |
223 | | - constructor = cast(_Constructor, getattr(cls, factory_method)) |
| 227 | + if entry.factory_method: |
| 228 | + constructor = cast( |
| 229 | + _Constructor, getattr(cls, entry.factory_method) |
| 230 | + ) |
224 | 231 | else: |
225 | 232 | constructor = cls |
226 | 233 |
|
227 | 234 | # Resolve arguments |
228 | | - kwargs = self._resolve_runtime(data, context=name) |
| 235 | + kwargs = self._resolve_runtime(entry.data, context=name) |
229 | 236 |
|
230 | 237 | try: |
231 | 238 | if isinstance(kwargs, dict): |
|
0 commit comments