anydi 0.27.0a1__py3-none-any.whl → 0.27.0a3__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/ext/faststream.py CHANGED
@@ -26,12 +26,22 @@ def install(broker: BrokerUsecase[Any, Any], container: Container) -> None:
26
26
  """
27
27
  broker._container = container # type: ignore[attr-defined]
28
28
 
29
- for subscriber in broker._subscribers.values(): # noqa
30
- call = subscriber.calls[0].handler._original_call # noqa
29
+ for handler in _get_broken_handlers(broker):
30
+ call = handler._original_call # noqa
31
31
  for parameter in get_typed_parameters(call):
32
32
  patch_call_parameter(call, parameter, container)
33
33
 
34
34
 
35
+ def _get_broken_handlers(broker: BrokerUsecase[Any, Any]) -> list[Any]:
36
+ if hasattr(broker, "handlers"):
37
+ return [handler.calls[0][0] for handler in broker.handlers.values()]
38
+ # faststream > 0.5.0
39
+ return [
40
+ subscriber.calls[0].handler
41
+ for subscriber in broker._subscribers.values() # noqa
42
+ ]
43
+
44
+
35
45
  def get_container(broker: BrokerUsecase[Any, Any]) -> Container:
36
46
  return cast(Container, getattr(broker, "_container")) # noqa
37
47
 
@@ -6,7 +6,6 @@ from typing import Any, Callable, Iterator, cast
6
6
  import pytest
7
7
 
8
8
  from anydi import Container
9
- from anydi._types import is_marker
10
9
  from anydi._utils import get_typed_parameters
11
10
 
12
11
 
@@ -24,12 +23,6 @@ def pytest_addoption(parser: pytest.Parser) -> None:
24
23
  type="bool",
25
24
  default=False,
26
25
  )
27
- parser.addini(
28
- "anydi_inject_auto",
29
- help="Automatically inject dependencies",
30
- type="bool",
31
- default=True,
32
- )
33
26
 
34
27
 
35
28
  CONTAINER_FIXTURE_NAME = "container"
@@ -71,17 +64,15 @@ def _anydi_injected_parameter_iterator(
71
64
  _anydi_unresolved: list[str],
72
65
  ) -> Callable[[], Iterator[tuple[str, Any]]]:
73
66
  registered_fixtures = request.session._fixturemanager._arg2fixturedefs # noqa
74
- inject_auto = cast(bool, request.config.getini("anydi_inject_auto"))
75
67
 
76
68
  def _iterator() -> Iterator[tuple[str, inspect.Parameter]]:
77
69
  for parameter in get_typed_parameters(request.function):
78
70
  interface = parameter.annotation
79
- if interface is parameter.empty:
80
- continue
81
- if not inject_auto and is_marker(parameter.default):
82
- yield parameter.name, interface
83
- continue
84
- if interface in _anydi_unresolved or parameter.name in registered_fixtures:
71
+ if (
72
+ interface is parameter.empty
73
+ or interface in _anydi_unresolved
74
+ or parameter.name in registered_fixtures
75
+ ):
85
76
  continue
86
77
  yield parameter.name, interface
87
78
 
@@ -104,17 +95,18 @@ def _anydi_inject(
104
95
  container = cast(Container, request.getfixturevalue("anydi_setup_container"))
105
96
 
106
97
  for argname, interface in _anydi_injected_parameter_iterator():
98
+ # Skip if the interface is not registered
99
+ if container.strict and not container.is_registered(interface):
100
+ continue
101
+
107
102
  # Release the instance if it was already resolved
108
103
  if container.is_resolved(interface):
109
104
  container.release(interface)
110
105
 
111
106
  try:
112
- # Resolve the instance
113
- instance = container.resolve(interface)
114
- except LookupError:
107
+ request.node.funcargs[argname] = container.resolve(interface)
108
+ except Exception: # noqa
115
109
  _anydi_unresolved.append(interface)
116
- continue
117
- request.node.funcargs[argname] = instance
118
110
 
119
111
 
120
112
  @pytest.fixture(autouse=True)
@@ -132,14 +124,15 @@ async def _anydi_ainject(
132
124
  container = cast(Container, request.getfixturevalue("anydi_setup_container"))
133
125
 
134
126
  for argname, interface in _anydi_injected_parameter_iterator():
127
+ # Skip if the interface is not registered
128
+ if container.strict and not container.is_registered(interface):
129
+ continue
130
+
135
131
  # Release the instance if it was already resolved
136
132
  if container.is_resolved(interface):
137
133
  container.release(interface)
138
134
 
139
135
  try:
140
- # Resolve the instance
141
- instance = await container.aresolve(interface)
142
- except LookupError:
136
+ request.node.funcargs[argname] = await container.aresolve(interface)
137
+ except Exception: # noqa
143
138
  _anydi_unresolved.append(interface)
144
- continue
145
- request.node.funcargs[argname] = instance
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.27.0a1
3
+ Version: 0.27.0a3
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -33,8 +33,8 @@ Provides-Extra: async
33
33
  Provides-Extra: docs
34
34
  Requires-Dist: anyio (>=3.6.2,<4.0.0) ; extra == "async"
35
35
  Requires-Dist: mkdocs (>=1.4.2,<2.0.0) ; extra == "docs"
36
- Requires-Dist: mkdocs-material (>=9.1.13,<10.0.0) ; extra == "docs"
37
- Requires-Dist: typing-extensions (>=4.8.0,<5.0.0)
36
+ Requires-Dist: mkdocs-material (>=9.5.21,<10.0.0) ; extra == "docs"
37
+ Requires-Dist: typing-extensions (>=4.12.1,<5.0.0)
38
38
  Project-URL: Repository, https://github.com/antonrh/anydi
39
39
  Description-Content-Type: text/markdown
40
40
 
@@ -18,13 +18,13 @@ anydi/ext/django/ninja/__init__.py,sha256=kW3grUgWp_nkWSG_-39ADHMrZLGNcj9TsJ9OW8
18
18
  anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI8W-oO2w,2696
19
19
  anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
20
20
  anydi/ext/fastapi.py,sha256=vhfSyovXuCjvSkx6AiLOTNU975i8wDg72C5fqXQiFLw,2896
21
- anydi/ext/faststream.py,sha256=svMtqFVSRTpuf4H5yeozHWmrBXi_F8cevb5d2mo3m-E,1617
22
- anydi/ext/pytest_plugin.py,sha256=AQVBsyEGoQdOvXpa2TlEPYMapzL7a-oKoVcvMnQ5Epk,4477
21
+ anydi/ext/faststream.py,sha256=Kuyqin6rKlOOM5x9BHIv-RF9i8zqU_kh4H6Xs0DLI20,1916
22
+ anydi/ext/pytest_plugin.py,sha256=pFLcfxGtJfGSqtk7sPrrHFSKOaZoKZTWt5X8CT0ydmA,4242
23
23
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
25
25
  anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
26
- anydi-0.27.0a1.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
27
- anydi-0.27.0a1.dist-info/METADATA,sha256=9k_8NOREjBfp2612k6n5nwFl3NfTWVQF8V9TrcNALh8,5162
28
- anydi-0.27.0a1.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
29
- anydi-0.27.0a1.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
30
- anydi-0.27.0a1.dist-info/RECORD,,
26
+ anydi-0.27.0a3.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
27
+ anydi-0.27.0a3.dist-info/METADATA,sha256=egpilYh24GazI0UAdIzX2gEBcND55qHX259hKihoVBo,5163
28
+ anydi-0.27.0a3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
29
+ anydi-0.27.0a3.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
30
+ anydi-0.27.0a3.dist-info/RECORD,,