python-injection 0.26.0__py3-none-any.whl → 0.26.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
injection/_core/scope.py CHANGED
@@ -212,6 +212,21 @@ def _bind_scope(
212
212
  stack.close()
213
213
 
214
214
 
215
+ class _SealedScopeCache(MutableMapping[Any, Any]):
216
+ __slots__ = ()
217
+
218
+ @staticmethod
219
+ def guard(*args: Any, **kwargs: Any) -> NoReturn:
220
+ raise ScopeError("Can't access cache of an exited scope.")
221
+
222
+ __delitem__ = __getitem__ = __iter__ = __len__ = __setitem__ = guard
223
+
224
+
225
+ _sealed_cache = _SealedScopeCache()
226
+
227
+ del _SealedScopeCache
228
+
229
+
215
230
  @runtime_checkable
216
231
  class Scope(Protocol):
217
232
  __slots__ = ()
@@ -227,14 +242,13 @@ class Scope(Protocol):
227
242
  raise NotImplementedError
228
243
 
229
244
 
230
- @dataclass(repr=False, frozen=True, slots=True)
245
+ @dataclass(repr=False, eq=False, slots=True)
231
246
  class BaseScope[T](Scope, ABC):
232
247
  delegate: T
233
- cache: MutableMapping[SlotKey[Any], Any] = field(
234
- default_factory=dict,
235
- init=False,
236
- hash=False,
237
- )
248
+ cache: MutableMapping[SlotKey[Any], Any] = field(default_factory=dict, init=False)
249
+
250
+ def close(self) -> None:
251
+ self.cache = _sealed_cache
238
252
 
239
253
 
240
254
  class AsyncScope(BaseScope[AsyncExitStack]):
@@ -253,6 +267,7 @@ class AsyncScope(BaseScope[AsyncExitStack]):
253
267
  exc_value: BaseException | None,
254
268
  traceback: TracebackType | None,
255
269
  ) -> Any:
270
+ self.close()
256
271
  return await self.delegate.__aexit__(exc_type, exc_value, traceback)
257
272
 
258
273
  async def aenter[T](self, context_manager: AsyncContextManager[T]) -> T:
@@ -278,6 +293,7 @@ class SyncScope(BaseScope[ExitStack]):
278
293
  exc_value: BaseException | None,
279
294
  traceback: TracebackType | None,
280
295
  ) -> Any:
296
+ self.close()
281
297
  return self.delegate.__exit__(exc_type, exc_value, traceback)
282
298
 
283
299
  async def aenter[T](self, context_manager: AsyncContextManager[T]) -> NoReturn:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.26.0
3
+ Version: 0.26.1
4
4
  Summary: Dead-simple dependency injection framework for Python.
5
5
  Project-URL: Documentation, https://python-injection.remimd.dev
6
6
  Project-URL: Repository, https://github.com/100nm/python-injection
@@ -10,7 +10,7 @@ injection/_core/descriptors.py,sha256=wpW6lFz7ZDDOh1Vc7P86z49UkZ1lajBReWOagSotWD
10
10
  injection/_core/injectables.py,sha256=t_A-tP7kNmNgjXUX_TKwZj3NU65RDpMUTqkVtvXGVNw,6435
11
11
  injection/_core/locator.py,sha256=pff_amjMi0XNXdIcPG8fK3vefRPwVLiZVvFg0qwEvDg,8258
12
12
  injection/_core/module.py,sha256=AJgAtoYmAzpCXMiazk2mlyW1aAiGuHK5XcvC5Vf-Ibo,28729
13
- injection/_core/scope.py,sha256=959UhEt1zY2lstP7zJgQJPGMv4s2fdv0gRL4f47GqRM,8517
13
+ injection/_core/scope.py,sha256=bYwo_BU22fTIWrMEJHrQl_axWs0UV1pmrNwmQQaXzA4,8925
14
14
  injection/_core/slots.py,sha256=g9TG6CbqRzCsjg01iPyfRtTTUCJnnJOwcj9mJabH0dc,37
15
15
  injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  injection/_core/common/asynchronous.py,sha256=nKY2_PAMFF2haC75Fwp8O9Zd-SDuenE6n3B-KccwXlw,1772
@@ -24,7 +24,7 @@ injection/ext/fastapi.py,sha256=wpiNyHKEPwQ7sAJt30XpkgiCi4-gfmyqkQWw9BejXwg,1633
24
24
  injection/ext/fastapi.pyi,sha256=HLs7mfruIEFRrN_Xf8oCvSa4qwHWfwm6HHU_KMedXkE,185
25
25
  injection/testing/__init__.py,sha256=ZWMacZuGhK8Edq1L0Ng0PaRlgKXEunyFZkFvx7-IYIQ,935
26
26
  injection/testing/__init__.pyi,sha256=ZFQMUZmvBVkV6Ch7jiYE9zeJhnqHAQnt3vWQ1Th0zDk,646
27
- python_injection-0.26.0.dist-info/METADATA,sha256=FzRj240iIOWO8HPpTxuAbpEYm-tmBkLHLRbADuoGQJw,3651
28
- python_injection-0.26.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
29
- python_injection-0.26.0.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
30
- python_injection-0.26.0.dist-info/RECORD,,
27
+ python_injection-0.26.1.dist-info/METADATA,sha256=44lKKLZUzMB20S-48w_syEjXUc454-8AxZ3LcKKu-AA,3651
28
+ python_injection-0.26.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
29
+ python_injection-0.26.1.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
30
+ python_injection-0.26.1.dist-info/RECORD,,