python-injection 0.10.6__py3-none-any.whl → 0.10.7__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
@@ -556,14 +556,14 @@ class Module(Broker, EventListener):
|
|
556
556
|
wp.__init__ = self.inject(wp.__init__)
|
557
557
|
return wp
|
558
558
|
|
559
|
-
|
559
|
+
injected = Injected(wp)
|
560
560
|
|
561
|
-
@
|
561
|
+
@injected.on_setup
|
562
562
|
def listen() -> None:
|
563
|
-
|
564
|
-
self.add_listener(
|
563
|
+
injected.update(self)
|
564
|
+
self.add_listener(injected)
|
565
565
|
|
566
|
-
return
|
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
|
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.
|
835
|
+
return self.__signature
|
858
836
|
|
859
837
|
with synchronized():
|
860
838
|
signature = inspect.signature(self.wrapped, eval_str=True)
|
861
|
-
self.
|
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.
|
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
|
-
|
966
|
-
|
967
|
-
|
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)
|
@@ -8,7 +8,7 @@ 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=p9pC1zb9tDZykHs5HGM5VpRxWyvuajC45vilvkvatkY,2999
|
11
|
-
injection/_core/module.py,sha256=
|
11
|
+
injection/_core/module.py,sha256=eXasRKjT-gNyM6-UhN8UN-EsQy56sREMZ0UVTpNq4SM,25031
|
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
|
@@ -17,6 +17,6 @@ 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.
|
21
|
-
python_injection-0.10.
|
22
|
-
python_injection-0.10.
|
20
|
+
python_injection-0.10.7.dist-info/METADATA,sha256=7DJYzpcPRTbBYtch0jct28aIqjvjqmLMLXPhhVKSavM,3059
|
21
|
+
python_injection-0.10.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
22
|
+
python_injection-0.10.7.dist-info/RECORD,,
|
File without changes
|