python-injection 0.19.1__py3-none-any.whl → 0.19.3__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.
@@ -2,20 +2,21 @@ from abc import abstractmethod
2
2
  from collections.abc import Callable
3
3
  from functools import wraps
4
4
  from inspect import iscoroutinefunction
5
+ from types import MethodType
5
6
  from typing import Any, Protocol, runtime_checkable
6
7
 
7
8
  from injection._core.common.asynchronous import Caller
8
9
  from injection._core.module import Module, mod
9
10
 
10
- type AsFunctionWrappedType[**P, T] = type[_Callable[P, T]]
11
+ type AsFunctionWrappedType[**P, T] = type[AsFunctionCallable[P, T]]
11
12
 
12
13
 
13
14
  @runtime_checkable
14
- class _Callable[**P, T](Protocol):
15
+ class AsFunctionCallable[**P, T](Protocol):
15
16
  __slots__ = ()
16
17
 
17
18
  @abstractmethod
18
- def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T:
19
+ def call(self, *args: P.args, **kwargs: P.kwargs) -> T:
19
20
  raise NotImplementedError
20
21
 
21
22
 
@@ -29,28 +30,27 @@ def asfunction[**P, T](
29
30
  module = module or mod()
30
31
 
31
32
  def decorator(wp: AsFunctionWrappedType[P, T]) -> Callable[P, T]:
32
- get_method = wp.__call__.__get__
33
- method = get_method(NotImplemented)
34
- factory: Caller[..., Callable[P, T]] = module.make_injected_function(
33
+ fake_method = MethodType(wp.call, NotImplemented)
34
+ factory: Caller[..., AsFunctionCallable[P, T]] = module.make_injected_function(
35
35
  wp,
36
36
  threadsafe=threadsafe,
37
37
  ).__inject_metadata__
38
38
 
39
39
  wrapper: Callable[P, T]
40
40
 
41
- if iscoroutinefunction(method):
41
+ if iscoroutinefunction(fake_method):
42
42
 
43
- @wraps(method)
43
+ @wraps(fake_method)
44
44
  async def wrapper(*args: P.args, **kwargs: P.kwargs) -> Any:
45
45
  self = await factory.acall()
46
- return await get_method(self)(*args, **kwargs)
46
+ return await self.call(*args, **kwargs) # type: ignore[misc]
47
47
 
48
48
  else:
49
49
 
50
- @wraps(method)
50
+ @wraps(fake_method)
51
51
  def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
52
52
  self = factory.call()
53
- return get_method(self)(*args, **kwargs)
53
+ return self.call(*args, **kwargs)
54
54
 
55
55
  wrapper.__name__ = wp.__name__
56
56
  wrapper.__qualname__ = wp.__qualname__
@@ -89,8 +89,16 @@ def standardize_types(
89
89
  else:
90
90
  yield tp
91
91
 
92
- if with_origin and origin is not None:
93
- yield origin
92
+ if with_origin:
93
+ if origin is not None:
94
+ yield origin
95
+
96
+ for alias in (tp, origin):
97
+ if isinstance(alias, TypeAliasType):
98
+ yield from standardize_types(
99
+ alias.__value__,
100
+ with_origin=with_origin,
101
+ )
94
102
 
95
103
  continue
96
104
 
injection/_core/module.py CHANGED
@@ -347,8 +347,8 @@ class Locator(Broker):
347
347
  @staticmethod
348
348
  def __standardize_inputs[T](
349
349
  classes: Iterable[InputType[T]],
350
- ) -> Iterable[InputType[T]]:
351
- return tuple(standardize_types(*classes, with_origin=True))
350
+ ) -> Iterator[InputType[T]]:
351
+ return standardize_types(*classes, with_origin=True)
352
352
 
353
353
  @staticmethod
354
354
  def __update_preprocessing[T](updater: Updater[T]) -> Updater[T]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.19.1
3
+ Version: 0.19.3
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -5,10 +5,10 @@ injection/exceptions.py,sha256=v57yMujiq6H_zwwn30A8UYEZX9R9k-bY8FnsdaimPM4,1025
5
5
  injection/loaders.py,sha256=gKlJfe9nXCuB8r6j0RF9_2FHC6YplM8GQYsgRqyxYw8,7257
6
6
  injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  injection/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- injection/_core/asfunction.py,sha256=oVDJcM8buR1OnKJPDOfQ61bbrKVEPzfgtE_H74O1HN4,1718
8
+ injection/_core/asfunction.py,sha256=fTgAAWsDWUz89kYsoSVDXdqYKIuh6HtUW5MohGp3ov4,1767
9
9
  injection/_core/descriptors.py,sha256=1OX6JnM8Ux14vW1JSW3FzPgKc2VMTKqJUYBGT3Ypafg,800
10
10
  injection/_core/injectables.py,sha256=fxhiGv7qTCbUunhhd6a3ahosFmgznUFsEvqlwxi4gS4,6098
11
- injection/_core/module.py,sha256=T9zvSOjMaPZiC_DCV7BIKOqCrmAHcYcleqgNro0MBgU,32624
11
+ injection/_core/module.py,sha256=yK3-WKi5vJoTSw6ESDQkJzp4uQeP8GdVRoO5BV6hXcM,32617
12
12
  injection/_core/scope.py,sha256=r094k1Vjvwm0hTf7AQGYrxxvqQgb7_CDVUKaHQ8wyeM,8772
13
13
  injection/_core/slots.py,sha256=g9TG6CbqRzCsjg01iPyfRtTTUCJnnJOwcj9mJabH0dc,37
14
14
  injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -18,13 +18,13 @@ injection/_core/common/invertible.py,sha256=gA_vw5nBjgp_w9MrDK5jMO8lhuOQWON8BbPp
18
18
  injection/_core/common/key.py,sha256=ghkZD-Y8Moz6SEPNgMh3xgsZUjDVq-XYAmXaCu5VuCA,80
19
19
  injection/_core/common/lazy.py,sha256=L7C2dB5UBI--W5Kkvntp_jypYhudY3SHqs8rM6jxxsk,965
20
20
  injection/_core/common/threading.py,sha256=kwRXNa9ocndIqeZA9kMHjEa8SBpHFcJARj1bgrWCpxE,225
21
- injection/_core/common/type.py,sha256=SCDtmBv9qFvEf5o5tTgCuwMDfuo1fgjSW0bUqA8ACis,2251
21
+ injection/_core/common/type.py,sha256=hlhzpWHgvdMKMVaGBSwFhgEur0Sruzj67Md-yV-1cNw,2550
22
22
  injection/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  injection/ext/fastapi.py,sha256=fiy3-mZIIwGcql3Y5ekFX8_7hALzqXP5u40qbtNE73o,1441
24
24
  injection/ext/fastapi.pyi,sha256=HLs7mfruIEFRrN_Xf8oCvSa4qwHWfwm6HHU_KMedXkE,185
25
25
  injection/testing/__init__.py,sha256=bJ7WXBXrw4rHc91AFVFnOwFLWOlpvX9Oh2SnRQ_NESo,919
26
26
  injection/testing/__init__.pyi,sha256=raGsGlxwbz3jkzJwA_5oCIE1emWINjT2UuwzbnqRb-0,577
27
- python_injection-0.19.1.dist-info/METADATA,sha256=5skunJb1mk9ovTHiGRielQzeImyZOTRDcd4HLg6EaO0,4301
28
- python_injection-0.19.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
- python_injection-0.19.1.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
30
- python_injection-0.19.1.dist-info/RECORD,,
27
+ python_injection-0.19.3.dist-info/METADATA,sha256=Ybbbf_GEZF9uEOexRMieKVXKh2by7czCpD7MTJQkECk,4301
28
+ python_injection-0.19.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ python_injection-0.19.3.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
30
+ python_injection-0.19.3.dist-info/RECORD,,