python-injection 0.10.6__tar.gz → 0.10.7__tar.gz

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.
Files changed (22) hide show
  1. {python_injection-0.10.6 → python_injection-0.10.7}/PKG-INFO +1 -1
  2. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/module.py +47 -57
  3. {python_injection-0.10.6 → python_injection-0.10.7}/pyproject.toml +1 -1
  4. {python_injection-0.10.6 → python_injection-0.10.7}/README.md +0 -0
  5. {python_injection-0.10.6 → python_injection-0.10.7}/injection/__init__.py +0 -0
  6. {python_injection-0.10.6 → python_injection-0.10.7}/injection/__init__.pyi +0 -0
  7. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/__init__.py +0 -0
  8. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/common/__init__.py +0 -0
  9. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/common/event.py +0 -0
  10. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/common/invertible.py +0 -0
  11. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/common/lazy.py +0 -0
  12. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/common/threading.py +0 -0
  13. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/common/type.py +0 -0
  14. {python_injection-0.10.6 → python_injection-0.10.7}/injection/_core/hook.py +0 -0
  15. {python_injection-0.10.6 → python_injection-0.10.7}/injection/exceptions.py +0 -0
  16. {python_injection-0.10.6 → python_injection-0.10.7}/injection/integrations/__init__.py +0 -0
  17. {python_injection-0.10.6 → python_injection-0.10.7}/injection/integrations/blacksheep.py +0 -0
  18. {python_injection-0.10.6 → python_injection-0.10.7}/injection/integrations/fastapi.py +0 -0
  19. {python_injection-0.10.6 → python_injection-0.10.7}/injection/py.typed +0 -0
  20. {python_injection-0.10.6 → python_injection-0.10.7}/injection/testing/__init__.py +0 -0
  21. {python_injection-0.10.6 → python_injection-0.10.7}/injection/testing/__init__.pyi +0 -0
  22. {python_injection-0.10.6 → python_injection-0.10.7}/injection/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-injection
3
- Version: 0.10.6
3
+ Version: 0.10.7
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Home-page: https://github.com/100nm/python-injection
6
6
  License: MIT
@@ -556,14 +556,14 @@ class Module(Broker, EventListener):
556
556
  wp.__init__ = self.inject(wp.__init__)
557
557
  return wp
558
558
 
559
- function = InjectedFunction(wp)
559
+ injected = Injected(wp)
560
560
 
561
- @function.on_setup
561
+ @injected.on_setup
562
562
  def listen() -> None:
563
- function.update(self)
564
- self.add_listener(function)
563
+ injected.update(self)
564
+ self.add_listener(injected)
565
565
 
566
- return function
566
+ return InjectedFunction(injected)
567
567
 
568
568
  return decorator(wrapped) if wrapped else decorator
569
569
 
@@ -587,7 +587,7 @@ class Module(Broker, EventListener):
587
587
  return Lazy(lambda: self.get_instance(cls))
588
588
 
589
589
  function = self.inject(lambda instance=None: instance)
590
- function.set_owner(cls)
590
+ function.__injected__.set_owner(cls)
591
591
  return SimpleInvertible(function)
592
592
 
593
593
  def update[T](self, updater: Updater[T]) -> Self:
@@ -803,68 +803,46 @@ class Arguments(NamedTuple):
803
803
  kwargs: Mapping[str, Any]
804
804
 
805
805
 
806
- class InjectedFunction[**P, T](EventListener):
806
+ class Injected[**P, T](EventListener):
807
807
  __slots__ = (
808
- "__dict__",
809
- "__wrapped__",
810
808
  "__dependencies",
811
809
  "__owner",
812
810
  "__setup_queue",
811
+ "__signature",
812
+ "__wrapped",
813
813
  )
814
814
 
815
- __signature__: Signature
816
- __wrapped__: Callable[P, T]
817
815
  __dependencies: Dependencies
818
816
  __owner: type | None
819
817
  __setup_queue: Queue[Callable[..., Any]] | None
818
+ __signature: Signature
819
+ __wrapped: Callable[P, T]
820
820
 
821
821
  def __init__(self, wrapped: Callable[P, T], /) -> None:
822
- update_wrapper(self, wrapped, updated=())
823
- self.__update_vars_from(wrapped)
824
822
  self.__dependencies = Dependencies.empty()
825
823
  self.__owner = None
826
824
  self.__setup_queue = Queue()
827
-
828
- @override
829
- def __repr__(self) -> str: # pragma: no cover
830
- return repr(self.wrapped)
831
-
832
- @override
833
- def __str__(self) -> str: # pragma: no cover
834
- return str(self.wrapped)
825
+ self.__wrapped = wrapped
835
826
 
836
827
  def __call__(self, /, *args: P.args, **kwargs: P.kwargs) -> T:
837
828
  self.__setup()
838
829
  arguments = self.bind(args, kwargs)
839
830
  return self.wrapped(*arguments.args, **arguments.kwargs)
840
831
 
841
- def __get__(
842
- self,
843
- instance: object | None = None,
844
- owner: type | None = None,
845
- ) -> Self | MethodType:
846
- if instance is None:
847
- return self
848
-
849
- return MethodType(self, instance)
850
-
851
- def __set_name__(self, owner: type, name: str) -> None:
852
- self.set_owner(owner)
853
-
854
832
  @property
855
833
  def signature(self) -> Signature:
856
834
  with suppress(AttributeError):
857
- return self.__signature__
835
+ return self.__signature
858
836
 
859
837
  with synchronized():
860
838
  signature = inspect.signature(self.wrapped, eval_str=True)
861
- self.__signature__ = signature
839
+ self.__signature = signature
862
840
 
863
841
  return signature
864
842
 
865
843
  @property
866
844
  def wrapped(self) -> Callable[P, T]:
867
- return self.__wrapped__
845
+ return self.__wrapped
868
846
 
869
847
  def bind(
870
848
  self,
@@ -944,24 +922,36 @@ class InjectedFunction[**P, T](EventListener):
944
922
  queue.join()
945
923
  self.__close_setup_queue()
946
924
 
947
- def __update_vars_from(self, obj: Any) -> None:
948
- try:
949
- variables = vars(obj)
950
- except TypeError:
951
- ...
952
- else:
953
- self.__update_vars(variables)
954
-
955
- def __update_vars(self, variables: Mapping[str, Any]) -> None:
956
- restricted_vars = frozenset(("__signature__", "__wrapped__")) | frozenset(
957
- var for var in dir(self) if not self.__is_dunder(var)
958
- )
959
- vars(self).update(
960
- (var, value)
961
- for var, value in variables.items()
962
- if var not in restricted_vars
963
- )
964
925
 
965
- @staticmethod
966
- def __is_dunder(var: str) -> bool:
967
- return var.startswith("__") and var.endswith("__")
926
+ class InjectedFunction[**P, T]:
927
+ __slots__ = ("__dict__", "__injected__")
928
+
929
+ __injected__: Injected[P, T]
930
+
931
+ def __init__(self, injected: Injected[P, T]) -> None:
932
+ update_wrapper(self, injected.wrapped)
933
+ self.__injected__ = injected
934
+
935
+ @override
936
+ def __repr__(self) -> str: # pragma: no cover
937
+ return repr(self.__injected__.wrapped)
938
+
939
+ @override
940
+ def __str__(self) -> str: # pragma: no cover
941
+ return str(self.__injected__.wrapped)
942
+
943
+ def __call__(self, /, *args: P.args, **kwargs: P.kwargs) -> T:
944
+ return self.__injected__(*args, **kwargs)
945
+
946
+ def __get__(
947
+ self,
948
+ instance: object | None = None,
949
+ owner: type | None = None,
950
+ ) -> Self | MethodType:
951
+ if instance is None:
952
+ return self
953
+
954
+ return MethodType(self, instance)
955
+
956
+ def __set_name__(self, owner: type, name: str) -> None:
957
+ self.__injected__.set_owner(owner)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "python-injection"
3
- version = "0.10.6"
3
+ version = "0.10.7"
4
4
  description = "Fast and easy dependency injection framework."
5
5
  license = "MIT"
6
6
  authors = ["remimd"]