python-injection 0.10.9__py3-none-any.whl → 0.10.11__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
injection/_core/module.py CHANGED
@@ -514,9 +514,10 @@ class Module(Broker, EventListener):
514
514
  mode: Mode | ModeStr = Mode.get_default(),
515
515
  ):
516
516
  def decorator(wp): # type: ignore[no-untyped-def]
517
- instance = wp()
518
- self.set_constant(
519
- instance,
517
+ lazy_instance = Lazy(wp)
518
+ self.injectable(
519
+ lambda: ~lazy_instance,
520
+ inject=False,
520
521
  on=on,
521
522
  mode=mode,
522
523
  )
@@ -28,10 +28,11 @@ def Inject[T]( # noqa: N802
28
28
 
29
29
 
30
30
  class InjectionDependency[T]:
31
- __slots__ = ("__call__", "__class")
31
+ __slots__ = ("__call__", "__class", "__module")
32
32
 
33
33
  __call__: Callable[[], T]
34
34
  __class: type[T] | TypeAliasType | GenericAlias
35
+ __module: Module
35
36
 
36
37
  __sentinel: ClassVar[object] = object()
37
38
 
@@ -39,15 +40,20 @@ class InjectionDependency[T]:
39
40
  lazy_instance = module.get_lazy_instance(cls, default=self.__sentinel)
40
41
  self.__call__ = lambda: self.__ensure(~lazy_instance)
41
42
  self.__class = cls
43
+ self.__module = module
42
44
 
43
45
  def __eq__(self, other: Any) -> bool:
44
46
  if isinstance(other, type(self)):
45
- return hash(self) == hash(other)
47
+ return self.__key == other.__key
46
48
 
47
49
  return NotImplemented
48
50
 
49
51
  def __hash__(self) -> int:
50
- return hash((self.__class,))
52
+ return hash(self.__key)
53
+
54
+ @property
55
+ def __key(self) -> tuple[type[T] | TypeAliasType | GenericAlias, Module]:
56
+ return self.__class, self.__module
51
57
 
52
58
  def __ensure(self, instance: T | Any) -> T:
53
59
  if instance is self.__sentinel:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-injection
3
- Version: 0.10.9
3
+ Version: 0.10.11
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Home-page: https://github.com/100nm/python-injection
6
6
  License: MIT
@@ -8,15 +8,15 @@ injection/_core/common/lazy.py,sha256=kCO1q4S6AdBhsP5RrihBJpgfeR4hxvMqSz1cpCgBdj
8
8
  injection/_core/common/threading.py,sha256=OXm7L3p8c7O7eSkU-RTR7cobqIGMhuo-7gpDXsWKDNQ,214
9
9
  injection/_core/common/type.py,sha256=TQTD-f_rnAHS0VgfkWxNFU8HAWPvkAktNDQ9_23JLHM,1705
10
10
  injection/_core/hook.py,sha256=_TcwhF_DONfcoBz58RxVLeA950Rs8wtZSLGepZwGBRk,3009
11
- injection/_core/module.py,sha256=c3YGhgSsZ8Cu5x-xaXHqJZEi3niSwH7HCVu6tj0IU0k,25243
11
+ injection/_core/module.py,sha256=JvawpGSt-TFLzUHOV79HtgUEDQ_lxv7H1xwwARaOwyw,25294
12
12
  injection/exceptions.py,sha256=-5Shs7R5rctQXhpMLfcjiMBCzrtFWxC88qETUIHz57s,692
13
13
  injection/integrations/__init__.py,sha256=NYLcstr4ESdLj326LlDub143z6JGM1z1pCOVWhBXK10,304
14
14
  injection/integrations/blacksheep.py,sha256=yO5gLb_l4W3bNPFt-v2qWIL9R8PNon4JmOxQEHdi-5o,923
15
- injection/integrations/fastapi.py,sha256=eg5m6pYJiblQvxJ8sVDgz-jH9MSrWju0wEMRmr4cVD8,1591
15
+ injection/integrations/fastapi.py,sha256=GIxpSOumBQ8r8ihBVAzbp0nd68x8YWh6zSfL7d6QLWs,1786
16
16
  injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  injection/testing/__init__.py,sha256=-C38gmZJwDtLDAWJhqiaosOZWQZwwFa1M34tODcrASs,747
18
18
  injection/testing/__init__.pyi,sha256=6ZXbbS-9ppMdkxd03I6yBNurmR3Xw7sM_qiokibkLeY,386
19
19
  injection/utils.py,sha256=gPcxGIdrGz4irbJXGTYPw33jNy8jg56u_c61eb1MBSE,1971
20
- python_injection-0.10.9.dist-info/METADATA,sha256=js6fr8O78PiY6UNGN2iG1ZsoFKm-jnklJHgTWM2QSKA,3110
21
- python_injection-0.10.9.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
22
- python_injection-0.10.9.dist-info/RECORD,,
20
+ python_injection-0.10.11.dist-info/METADATA,sha256=eI7fVqQkkS20p6JS596mL6GyYd8EJdjaCgmEmxO5lWE,3111
21
+ python_injection-0.10.11.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
22
+ python_injection-0.10.11.dist-info/RECORD,,