python-injection 0.14.1__py3-none-any.whl → 0.14.2__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/module.py CHANGED
@@ -73,6 +73,7 @@ from injection.exceptions import (
73
73
  ModuleLockError,
74
74
  ModuleNotUsedError,
75
75
  NoInjectable,
76
+ SkipInjectable,
76
77
  )
77
78
 
78
79
  """
@@ -620,7 +621,7 @@ class Module(Broker, EventListener):
620
621
  async def aget_instance(self, cls, default=None): # type: ignore[no-untyped-def]
621
622
  try:
622
623
  return await self.afind_instance(cls)
623
- except KeyError:
624
+ except (KeyError, SkipInjectable):
624
625
  return default
625
626
 
626
627
  @overload
@@ -640,7 +641,7 @@ class Module(Broker, EventListener):
640
641
  def get_instance(self, cls, default=None): # type: ignore[no-untyped-def]
641
642
  try:
642
643
  return self.find_instance(cls)
643
- except KeyError:
644
+ except (KeyError, SkipInjectable):
644
645
  return default
645
646
 
646
647
  @overload
@@ -866,29 +867,28 @@ class Dependencies:
866
867
  lazy_mapping: Lazy[Mapping[str, Injectable[Any]]]
867
868
 
868
869
  def __iter__(self) -> Iterator[tuple[str, Any]]:
869
- for name, injectable in self.mapping.items():
870
- instance = injectable.get_instance()
871
- yield name, instance
870
+ for name, injectable in self.items():
871
+ with suppress(SkipInjectable):
872
+ yield name, injectable.get_instance()
872
873
 
873
874
  async def __aiter__(self) -> AsyncIterator[tuple[str, Any]]:
874
- for name, injectable in self.mapping.items():
875
- instance = await injectable.aget_instance()
876
- yield name, instance
875
+ for name, injectable in self.items():
876
+ with suppress(SkipInjectable):
877
+ yield name, await injectable.aget_instance()
877
878
 
878
879
  @property
879
880
  def are_resolved(self) -> bool:
880
881
  return self.lazy_mapping.is_set
881
882
 
882
- @property
883
- def mapping(self) -> Mapping[str, Injectable[Any]]:
884
- return ~self.lazy_mapping
885
-
886
883
  async def aget_arguments(self) -> dict[str, Any]:
887
884
  return {key: value async for key, value in self}
888
885
 
889
886
  def get_arguments(self) -> dict[str, Any]:
890
887
  return dict(self)
891
888
 
889
+ def items(self) -> Iterator[tuple[str, Injectable[Any]]]:
890
+ return iter((~self.lazy_mapping).items())
891
+
892
892
  @classmethod
893
893
  def from_iterable(cls, iterable: Iterable[tuple[str, Injectable[Any]]]) -> Self:
894
894
  lazy_mapping = Lazy(lambda: dict(iterable))
injection/exceptions.py CHANGED
@@ -10,6 +10,7 @@ __all__ = (
10
10
  "ScopeAlreadyDefinedError",
11
11
  "ScopeError",
12
12
  "ScopeUndefinedError",
13
+ "SkipInjectable",
13
14
  )
14
15
 
15
16
 
@@ -30,6 +31,9 @@ class NoInjectable[T](KeyError, InjectionError):
30
31
  return self.__class
31
32
 
32
33
 
34
+ class SkipInjectable(InjectionError): ...
35
+
36
+
33
37
  class ModuleError(InjectionError): ...
34
38
 
35
39
 
@@ -42,7 +46,7 @@ class ModuleNotUsedError(KeyError, ModuleError): ...
42
46
  class ScopeError(InjectionError): ...
43
47
 
44
48
 
45
- class ScopeUndefinedError(LookupError, ScopeError): ...
49
+ class ScopeUndefinedError(LookupError, SkipInjectable, ScopeError): ...
46
50
 
47
51
 
48
52
  class ScopeAlreadyDefinedError(ScopeError): ...
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.14.1
3
+ Version: 0.14.2
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -1,13 +1,13 @@
1
1
  injection/__init__.py,sha256=X0vIAoN4MDlhR7YIkup1qHgqbOkwZ3PWgdSi7h-udaM,1049
2
2
  injection/__init__.pyi,sha256=6B5GdRNaAJ15Q-QAL8nNpTBVIKEUPJAwWIlCSjOkkJ8,10058
3
- injection/exceptions.py,sha256=T__732aXxWWUz0sKc39ySteyolCS5tpqQC0oCnzUF2E,917
3
+ injection/exceptions.py,sha256=dp9XYpWHh8R76wbWDJdjmpTHGQp8KuCeveTqarXY_6Y,999
4
4
  injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  injection/utils.py,sha256=Lr0qHaq3_1AkUoAaw2XmMNie_alwYTeTrRlO22FeCnk,2762
6
6
  injection/_core/__init__.py,sha256=XERocCxCZBxPGIaOR37yeiQOZyvjHQ6a4rgRmlkUSuU,1367
7
7
  injection/_core/descriptors.py,sha256=7fSHlgAqmgR_Uta8KocBapOt1Xyj2dI7RY9ZdoStTzw,726
8
8
  injection/_core/hook.py,sha256=rJyaSwFAHM8qizWANPUSt5KzWdjxc5oJ2U8hcGeZjU8,3097
9
9
  injection/_core/injectables.py,sha256=GIumNp0TXf8Voxe1sCPhcqq2gyw4E_hl7I45IJ_tyHE,4512
10
- injection/_core/module.py,sha256=Dxpdtsft-BaaPRj2v1YFepF1y1s7QINoa9iDxQLGJjM,31154
10
+ injection/_core/module.py,sha256=1eGb4IHVCJByHUnAG83-oPgp8VbZty8x1YZ6OFT0zEU,31232
11
11
  injection/_core/scope.py,sha256=pwOqVKOUM_ZteNScgp-hLqyOHg5Ew75jWlfWLLD2PU8,5437
12
12
  injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  injection/_core/common/asynchronous.py,sha256=9bQDVRE6eqo9K0d5H9RzyFalf0WGoGP7cDrKDGbvZPI,1500
@@ -20,6 +20,6 @@ injection/integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3
20
20
  injection/integrations/fastapi.py,sha256=YHSs85_3m6TUVtOwUcV157b3UZJQIw_aXWAg199a-YE,594
21
21
  injection/testing/__init__.py,sha256=Bh3JqEXw62-JnUnspOXr2jpjGXZJ_K_K9CgfD7dPZeQ,793
22
22
  injection/testing/__init__.pyi,sha256=1h9zNGghxlo4D1jAx5s8EHk54mn7o-qO7WgJa6hwX6U,484
23
- python_injection-0.14.1.dist-info/METADATA,sha256=CMClwSxU8s_yCBYsduNEXc1426OeyWQzGFHTlQxe1eo,3199
24
- python_injection-0.14.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
- python_injection-0.14.1.dist-info/RECORD,,
23
+ python_injection-0.14.2.dist-info/METADATA,sha256=9IhlCQv8o9QERwHq1RZwXB83mmrz4stiLxnoKKhX6sI,3199
24
+ python_injection-0.14.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
25
+ python_injection-0.14.2.dist-info/RECORD,,