python-injection 0.10.9__tar.gz → 0.10.11__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. {python_injection-0.10.9 → python_injection-0.10.11}/PKG-INFO +1 -1
  2. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/module.py +4 -3
  3. {python_injection-0.10.9 → python_injection-0.10.11}/injection/integrations/fastapi.py +9 -3
  4. {python_injection-0.10.9 → python_injection-0.10.11}/pyproject.toml +2 -1
  5. {python_injection-0.10.9 → python_injection-0.10.11}/README.md +0 -0
  6. {python_injection-0.10.9 → python_injection-0.10.11}/injection/__init__.py +0 -0
  7. {python_injection-0.10.9 → python_injection-0.10.11}/injection/__init__.pyi +0 -0
  8. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/__init__.py +0 -0
  9. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/common/__init__.py +0 -0
  10. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/common/event.py +0 -0
  11. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/common/invertible.py +0 -0
  12. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/common/lazy.py +0 -0
  13. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/common/threading.py +0 -0
  14. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/common/type.py +0 -0
  15. {python_injection-0.10.9 → python_injection-0.10.11}/injection/_core/hook.py +0 -0
  16. {python_injection-0.10.9 → python_injection-0.10.11}/injection/exceptions.py +0 -0
  17. {python_injection-0.10.9 → python_injection-0.10.11}/injection/integrations/__init__.py +0 -0
  18. {python_injection-0.10.9 → python_injection-0.10.11}/injection/integrations/blacksheep.py +0 -0
  19. {python_injection-0.10.9 → python_injection-0.10.11}/injection/py.typed +0 -0
  20. {python_injection-0.10.9 → python_injection-0.10.11}/injection/testing/__init__.py +0 -0
  21. {python_injection-0.10.9 → python_injection-0.10.11}/injection/testing/__init__.pyi +0 -0
  22. {python_injection-0.10.9 → python_injection-0.10.11}/injection/utils.py +0 -0
@@ -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
@@ -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
  [tool.poetry]
2
2
  name = "python-injection"
3
- version = "0.10.9"
3
+ version = "0.10.11"
4
4
  description = "Fast and easy dependency injection framework."
5
5
  license = "MIT"
6
6
  authors = ["remimd"]
@@ -54,6 +54,7 @@ exclude_lines = [
54
54
  "pass",
55
55
  "pragma: no cover",
56
56
  "raise NotImplementedError",
57
+ "return NotImplemented",
57
58
  ]
58
59
 
59
60
  [tool.coverage.run]