anydi 0.52.0__tar.gz → 0.53.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anydi
3
- Version: 0.52.0
3
+ Version: 0.53.0
4
4
  Summary: Dependency Injection library
5
5
  Keywords: dependency injection,dependencies,di,async,asyncio,application
6
6
  Author: Anton Ruhlov
@@ -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
- globalns = getattr(call, "__globals__", {})
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 get_typed_parameters(call):
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
  )
@@ -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 get_typed_parameters, is_inject_marker
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 param in get_typed_parameters(member):
107
- if is_inject_marker(param.default):
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
@@ -3,9 +3,11 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import inspect
6
- from collections.abc import AsyncIterator, Callable, Iterator
6
+ from collections.abc import AsyncIterator, Iterator
7
7
  from types import NoneType
8
- from typing import Any, ForwardRef
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
- def get_typed_annotation(
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:
@@ -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, get_typed_parameters
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 get_typed_parameters(call):
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
 
@@ -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, get_typed_parameters
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 get_typed_parameters(call):
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
 
@@ -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 get_typed_parameters(request.function):
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,6 +1,6 @@
1
1
  [project]
2
2
  name = "anydi"
3
- version = "0.52.0"
3
+ version = "0.53.0"
4
4
  description = "Dependency Injection library"
5
5
  authors = [{ name = "Anton Ruhlov", email = "antonruhlov@gmail.com" }]
6
6
  requires-python = ">=3.10.0, <3.15"
@@ -51,7 +51,7 @@ anydi = "anydi.ext.pytest_plugin"
51
51
  [dependency-groups]
52
52
  dev = [
53
53
  "ruff>=0.14.0",
54
- "pyright>=1.1.406",
54
+ "pyright>=1.1.407",
55
55
  "pytest>=8.4.0,<9",
56
56
  "pytest-cov>=7.0.0",
57
57
  "pytest-mock>=3.14.1",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes