anydi 0.52.0__py3-none-any.whl → 0.53.0__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.
- anydi/_container.py +2 -13
- anydi/_scan.py +3 -3
- anydi/_typing.py +5 -43
- anydi/ext/fastapi.py +3 -2
- anydi/ext/faststream.py +3 -2
- anydi/ext/pytest_plugin.py +3 -2
- {anydi-0.52.0.dist-info → anydi-0.53.0.dist-info}/METADATA +1 -1
- {anydi-0.52.0.dist-info → anydi-0.53.0.dist-info}/RECORD +10 -10
- {anydi-0.52.0.dist-info → anydi-0.53.0.dist-info}/WHEEL +0 -0
- {anydi-0.52.0.dist-info → anydi-0.53.0.dist-info}/entry_points.txt +0 -0
anydi/_container.py
CHANGED
|
@@ -25,8 +25,6 @@ from ._scope import ALLOWED_SCOPES, Scope
|
|
|
25
25
|
from ._typing import (
|
|
26
26
|
NOT_SET,
|
|
27
27
|
Event,
|
|
28
|
-
get_typed_annotation,
|
|
29
|
-
get_typed_parameters,
|
|
30
28
|
is_async_context_manager,
|
|
31
29
|
is_context_manager,
|
|
32
30
|
is_event_type,
|
|
@@ -264,9 +262,7 @@ class Container:
|
|
|
264
262
|
self._validate_provider_scope(scope, name, kind)
|
|
265
263
|
|
|
266
264
|
# Get the signature
|
|
267
|
-
|
|
268
|
-
module = getattr(call, "__module__", None)
|
|
269
|
-
signature = inspect.signature(call, globals=globalns)
|
|
265
|
+
signature = inspect.signature(call, eval_str=True)
|
|
270
266
|
|
|
271
267
|
# Detect the interface
|
|
272
268
|
if interface is NOT_SET:
|
|
@@ -277,9 +273,6 @@ class Container:
|
|
|
277
273
|
if interface is inspect.Signature.empty:
|
|
278
274
|
interface = None
|
|
279
275
|
|
|
280
|
-
if isinstance(interface, str):
|
|
281
|
-
interface = get_typed_annotation(interface, globalns, module)
|
|
282
|
-
|
|
283
276
|
# If the callable is an iterator, return the actual type
|
|
284
277
|
if is_iterator_type(interface) or is_iterator_type(get_origin(interface)):
|
|
285
278
|
if args := get_args(interface):
|
|
@@ -320,10 +313,6 @@ class Container:
|
|
|
320
313
|
f"are not allowed in the provider `{name}`."
|
|
321
314
|
)
|
|
322
315
|
|
|
323
|
-
parameter = parameter.replace(
|
|
324
|
-
annotation=get_typed_annotation(parameter.annotation, globalns, module)
|
|
325
|
-
)
|
|
326
|
-
|
|
327
316
|
try:
|
|
328
317
|
sub_provider = self._get_or_register_provider(parameter.annotation)
|
|
329
318
|
except LookupError as exc:
|
|
@@ -777,7 +766,7 @@ class Container:
|
|
|
777
766
|
def _get_injected_params(self, call: Callable[..., Any]) -> dict[str, Any]:
|
|
778
767
|
"""Get the injected parameters of a callable object."""
|
|
779
768
|
injected_params: dict[str, Any] = {}
|
|
780
|
-
for parameter in
|
|
769
|
+
for parameter in inspect.signature(call, eval_str=True).parameters.values():
|
|
781
770
|
interface, should_inject = self.validate_injected_parameter(
|
|
782
771
|
parameter, call=call
|
|
783
772
|
)
|
anydi/_scan.py
CHANGED
|
@@ -9,7 +9,7 @@ from types import ModuleType
|
|
|
9
9
|
from typing import TYPE_CHECKING, Any
|
|
10
10
|
|
|
11
11
|
from ._decorators import is_injectable
|
|
12
|
-
from ._typing import
|
|
12
|
+
from ._typing import is_inject_marker
|
|
13
13
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
15
|
from ._container import Container
|
|
@@ -103,8 +103,8 @@ class Scanner:
|
|
|
103
103
|
# If no tags are passed and not explicitly injectable,
|
|
104
104
|
# check for parameter markers
|
|
105
105
|
if not tags:
|
|
106
|
-
for
|
|
107
|
-
if is_inject_marker(
|
|
106
|
+
for parameter in inspect.signature(member).parameters.values():
|
|
107
|
+
if is_inject_marker(parameter.default):
|
|
108
108
|
return True
|
|
109
109
|
|
|
110
110
|
return False
|
anydi/_typing.py
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import inspect
|
|
6
|
-
from collections.abc import AsyncIterator,
|
|
6
|
+
from collections.abc import AsyncIterator, Iterator
|
|
7
7
|
from types import NoneType
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from typing_extensions import Sentinel
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
def is_context_manager(obj: Any) -> bool:
|
|
@@ -28,47 +30,7 @@ def is_iterator_type(tp: Any) -> bool:
|
|
|
28
30
|
return tp in (Iterator, AsyncIterator)
|
|
29
31
|
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
annotation: Any, globalns: dict[str, Any], module: Any = None
|
|
33
|
-
) -> Any:
|
|
34
|
-
"""Get the typed annotation of a callable object."""
|
|
35
|
-
if isinstance(annotation, str):
|
|
36
|
-
ref = ForwardRef(annotation, module=module)
|
|
37
|
-
annotation = ref._evaluate(globalns, globalns, recursive_guard=frozenset()) # type: ignore[reportDeprecated]
|
|
38
|
-
return annotation
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def get_typed_parameters(obj: Callable[..., Any]) -> list[inspect.Parameter]:
|
|
42
|
-
"""Get the typed parameters of a callable object."""
|
|
43
|
-
globalns = getattr(obj, "__globals__", {})
|
|
44
|
-
module = getattr(obj, "__module__", None)
|
|
45
|
-
return [
|
|
46
|
-
parameter.replace(
|
|
47
|
-
annotation=get_typed_annotation(
|
|
48
|
-
parameter.annotation, globalns, module=module
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
for parameter in inspect.signature(obj).parameters.values()
|
|
52
|
-
]
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
class _Sentinel:
|
|
56
|
-
__slots__ = ("_name",)
|
|
57
|
-
|
|
58
|
-
def __init__(self, name: str) -> None:
|
|
59
|
-
self._name = name
|
|
60
|
-
|
|
61
|
-
def __repr__(self) -> str:
|
|
62
|
-
return f"<{self._name}>"
|
|
63
|
-
|
|
64
|
-
def __eq__(self, other: object) -> bool:
|
|
65
|
-
return self is other
|
|
66
|
-
|
|
67
|
-
def __hash__(self) -> int:
|
|
68
|
-
return id(self)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
NOT_SET = _Sentinel("NOT_SET")
|
|
33
|
+
NOT_SET = Sentinel("NOT_SET")
|
|
72
34
|
|
|
73
35
|
|
|
74
36
|
class InjectMarker:
|
anydi/ext/fastapi.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import inspect
|
|
5
6
|
from collections.abc import Iterator
|
|
6
7
|
from typing import Annotated, Any, cast
|
|
7
8
|
|
|
@@ -11,7 +12,7 @@ from fastapi.routing import APIRoute
|
|
|
11
12
|
from starlette.requests import Request
|
|
12
13
|
|
|
13
14
|
from anydi._container import Container
|
|
14
|
-
from anydi._typing import InjectMarker
|
|
15
|
+
from anydi._typing import InjectMarker
|
|
15
16
|
|
|
16
17
|
from .starlette.middleware import RequestScopedMiddleware
|
|
17
18
|
|
|
@@ -39,7 +40,7 @@ def install(app: FastAPI, container: Container) -> None:
|
|
|
39
40
|
call, *params = dependant.cache_key
|
|
40
41
|
if not call:
|
|
41
42
|
continue # pragma: no cover
|
|
42
|
-
for parameter in
|
|
43
|
+
for parameter in inspect.signature(call, eval_str=True).parameters.values():
|
|
43
44
|
container.validate_injected_parameter(parameter, call=call)
|
|
44
45
|
|
|
45
46
|
|
anydi/ext/faststream.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import inspect
|
|
5
6
|
from typing import Any, cast
|
|
6
7
|
|
|
7
8
|
from fast_depends.dependencies import Depends
|
|
@@ -9,7 +10,7 @@ from faststream import ContextRepo
|
|
|
9
10
|
from faststream.broker.core.usecase import BrokerUsecase
|
|
10
11
|
|
|
11
12
|
from anydi import Container
|
|
12
|
-
from anydi._typing import InjectMarker
|
|
13
|
+
from anydi._typing import InjectMarker
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def install(broker: BrokerUsecase[Any, Any], container: Container) -> None:
|
|
@@ -23,7 +24,7 @@ def install(broker: BrokerUsecase[Any, Any], container: Container) -> None:
|
|
|
23
24
|
|
|
24
25
|
for handler in _get_broken_handlers(broker):
|
|
25
26
|
call = handler._original_call # noqa
|
|
26
|
-
for parameter in
|
|
27
|
+
for parameter in inspect.signature(call, eval_str=True).parameters.values():
|
|
27
28
|
container.validate_injected_parameter(parameter, call=call)
|
|
28
29
|
|
|
29
30
|
|
anydi/ext/pytest_plugin.py
CHANGED
|
@@ -9,7 +9,6 @@ import pytest
|
|
|
9
9
|
from anyio.pytest_plugin import extract_backend_and_options, get_runner
|
|
10
10
|
|
|
11
11
|
from anydi import Container
|
|
12
|
-
from anydi._typing import get_typed_parameters
|
|
13
12
|
|
|
14
13
|
logger = logging.getLogger(__name__)
|
|
15
14
|
|
|
@@ -61,7 +60,9 @@ def _anydi_injected_parameter_iterator(
|
|
|
61
60
|
)
|
|
62
61
|
|
|
63
62
|
def _iterator() -> Iterator[tuple[str, inspect.Parameter]]:
|
|
64
|
-
for parameter in
|
|
63
|
+
for parameter in inspect.signature(
|
|
64
|
+
request.function, eval_str=True
|
|
65
|
+
).parameters.values():
|
|
65
66
|
interface = parameter.annotation
|
|
66
67
|
if (
|
|
67
68
|
interface is inspect.Parameter.empty
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
anydi/__init__.py,sha256=KjjYm-1yAFxiPYaMs1WRJMtxE0q_vdX7ZRLQR1fFGs8,567
|
|
2
2
|
anydi/_async.py,sha256=lrKTrqMC81POFbea3kaC9KkY3sp0DaenuVPvwOg88xA,1472
|
|
3
|
-
anydi/_container.py,sha256=
|
|
3
|
+
anydi/_container.py,sha256=a_HH_gYwWcruub7pEpA0rCe6MqLc7D5pp9lRgrrbxLs,31554
|
|
4
4
|
anydi/_context.py,sha256=_Xy8cTpRskb4cxTd-Fe-5NnIZyBe1DnovkofhdeUfmw,3020
|
|
5
5
|
anydi/_decorators.py,sha256=yxY876_2fzC30UIb4-4mR-J5ToQN3BH61E2cFH-iX8Y,2809
|
|
6
6
|
anydi/_module.py,sha256=2kN5uEXLd2Dsc58gz5IWK43wJewr_QgIVGSO3iWp798,2609
|
|
7
7
|
anydi/_provider.py,sha256=BWW4nXJ5r-0tCgS91kLWzYbrGv1v1oIm8BSt1cyYkDc,2150
|
|
8
|
-
anydi/_scan.py,sha256=
|
|
8
|
+
anydi/_scan.py,sha256=BLayc0NY_NYicr-ApX7Ztco9sd0izSZKGB-pUktui_s,3637
|
|
9
9
|
anydi/_scope.py,sha256=PFHjPb2-n0vhRo9mvD_craTFfoJBzR3y-N3_0apL5Q0,258
|
|
10
|
-
anydi/_typing.py,sha256=
|
|
10
|
+
anydi/_typing.py,sha256=I0Qt3Ec6ki6ZXf0Krm-LUIPRvzvyUUHfKdvmQijBErQ,1718
|
|
11
11
|
anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
12
12
|
anydi/ext/django/__init__.py,sha256=Ve8lncLU9dPY_Vjt4zihPgsSxwAtFHACn0XvBM5JG8k,367
|
|
13
|
-
anydi/ext/fastapi.py,sha256=
|
|
14
|
-
anydi/ext/faststream.py,sha256=
|
|
13
|
+
anydi/ext/fastapi.py,sha256=pdYumpXMAw2VjlDlb8u3R_RQi6htRieiZKsSA-9BSdA,2349
|
|
14
|
+
anydi/ext/faststream.py,sha256=CEuGjVZRbgSjkeV1rSp6xWggGYoKnBDeo3PiPgKtxuc,1930
|
|
15
15
|
anydi/ext/pydantic_settings.py,sha256=0GQjw7QpQlT5p6GxFClXYdtc6J42PClmAnRWPEzMjvY,1488
|
|
16
|
-
anydi/ext/pytest_plugin.py,sha256=
|
|
16
|
+
anydi/ext/pytest_plugin.py,sha256=amQT0GQuBrpvhchJyBy1IfqnTwFHKpUotGfOAxltL58,4739
|
|
17
17
|
anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
18
|
anydi/ext/starlette/middleware.py,sha256=MxnzshAs-CMvjJp0r457k52MzBL8O4KAuClnF6exBdU,803
|
|
19
19
|
anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
20
|
anydi/testing.py,sha256=gbQnJ6qFaQ5qbUwFWfSJ67SKhxLuPzwLGidistsmHk8,5519
|
|
21
|
-
anydi-0.
|
|
22
|
-
anydi-0.
|
|
23
|
-
anydi-0.
|
|
24
|
-
anydi-0.
|
|
21
|
+
anydi-0.53.0.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
22
|
+
anydi-0.53.0.dist-info/entry_points.txt,sha256=AgOcQYM5KyS4D37QcYb00tiid0QA-pD1VrjHHq4QAps,44
|
|
23
|
+
anydi-0.53.0.dist-info/METADATA,sha256=ZIUAp0tDmkV0sHCaYZvwAzBGQPasiMFXondsFUibcgM,5022
|
|
24
|
+
anydi-0.53.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|