anydi 0.26.1__py3-none-any.whl → 0.26.2__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 +11 -1
- anydi/ext/pytest_plugin.py +23 -20
- {anydi-0.26.1.dist-info → anydi-0.26.2.dist-info}/METADATA +1 -1
- {anydi-0.26.1.dist-info → anydi-0.26.2.dist-info}/RECORD +7 -7
- {anydi-0.26.1.dist-info → anydi-0.26.2.dist-info}/LICENSE +0 -0
- {anydi-0.26.1.dist-info → anydi-0.26.2.dist-info}/WHEEL +0 -0
- {anydi-0.26.1.dist-info → anydi-0.26.2.dist-info}/entry_points.txt +0 -0
anydi/_container.py
CHANGED
|
@@ -225,7 +225,7 @@ class Container:
|
|
|
225
225
|
scoped_context.delete(interface)
|
|
226
226
|
|
|
227
227
|
# Cleanup provider references
|
|
228
|
-
self.
|
|
228
|
+
self._delete_provider(interface)
|
|
229
229
|
|
|
230
230
|
def _get_provider(self, interface: AnyInterface) -> Provider:
|
|
231
231
|
"""Get provider by interface.
|
|
@@ -288,6 +288,16 @@ class Container:
|
|
|
288
288
|
if provider.is_resource:
|
|
289
289
|
self._providers_cache[provider.scope].append(interface)
|
|
290
290
|
|
|
291
|
+
def _delete_provider(self, interface: AnyInterface) -> None:
|
|
292
|
+
"""Delete a provider by interface.
|
|
293
|
+
|
|
294
|
+
Args:
|
|
295
|
+
interface: The interface for which to delete the provider.
|
|
296
|
+
"""
|
|
297
|
+
provider = self._providers.pop(interface, None)
|
|
298
|
+
if provider is not None and provider.is_resource:
|
|
299
|
+
self._providers_cache[provider.scope].remove(interface)
|
|
300
|
+
|
|
291
301
|
def _validate_provider_scope(self, provider: Provider) -> None:
|
|
292
302
|
"""Validate the scope of a provider.
|
|
293
303
|
|
anydi/ext/pytest_plugin.py
CHANGED
|
@@ -63,12 +63,15 @@ def _anydi_injected_parameter_iterator(
|
|
|
63
63
|
request: pytest.FixtureRequest,
|
|
64
64
|
_anydi_unresolved: list[str],
|
|
65
65
|
) -> Callable[[], Iterator[tuple[str, Any]]]:
|
|
66
|
+
registered_fixtures = request.session._fixturemanager._arg2fixturedefs # noqa
|
|
67
|
+
|
|
66
68
|
def _iterator() -> Iterator[tuple[str, inspect.Parameter]]:
|
|
67
69
|
for parameter in get_typed_parameters(request.function):
|
|
70
|
+
interface = parameter.annotation
|
|
68
71
|
if (
|
|
69
|
-
|
|
72
|
+
interface is parameter.empty
|
|
70
73
|
or interface in _anydi_unresolved
|
|
71
|
-
or parameter.name in
|
|
74
|
+
or parameter.name in registered_fixtures
|
|
72
75
|
):
|
|
73
76
|
continue
|
|
74
77
|
yield parameter.name, interface
|
|
@@ -92,18 +95,18 @@ def _anydi_inject(
|
|
|
92
95
|
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
93
96
|
|
|
94
97
|
for argname, interface in _anydi_injected_parameter_iterator():
|
|
95
|
-
|
|
96
|
-
|
|
98
|
+
# Skip if the interface is not registered
|
|
99
|
+
if container.strict and not container.is_registered(interface):
|
|
100
|
+
continue
|
|
101
|
+
|
|
102
|
+
# Release the instance if it was already resolved
|
|
103
|
+
if container.is_resolved(interface):
|
|
97
104
|
container.release(interface)
|
|
98
|
-
|
|
99
|
-
pass
|
|
105
|
+
|
|
100
106
|
try:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
except LookupError:
|
|
107
|
+
request.node.funcargs[argname] = container.resolve(interface)
|
|
108
|
+
except Exception: # noqa
|
|
104
109
|
_anydi_unresolved.append(interface)
|
|
105
|
-
continue
|
|
106
|
-
request.node.funcargs[argname] = instance
|
|
107
110
|
|
|
108
111
|
|
|
109
112
|
@pytest.fixture(autouse=True)
|
|
@@ -121,15 +124,15 @@ async def _anydi_ainject(
|
|
|
121
124
|
container = cast(Container, request.getfixturevalue("anydi_setup_container"))
|
|
122
125
|
|
|
123
126
|
for argname, interface in _anydi_injected_parameter_iterator():
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
# Skip if the interface is not registered
|
|
128
|
+
if container.strict and not container.is_registered(interface):
|
|
129
|
+
continue
|
|
130
|
+
|
|
131
|
+
# Release the instance if it was already resolved
|
|
132
|
+
if container.is_resolved(interface):
|
|
126
133
|
container.release(interface)
|
|
127
|
-
|
|
128
|
-
pass
|
|
134
|
+
|
|
129
135
|
try:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
except LookupError:
|
|
136
|
+
request.node.funcargs[argname] = await container.aresolve(interface)
|
|
137
|
+
except Exception: # noqa
|
|
133
138
|
_anydi_unresolved.append(interface)
|
|
134
|
-
continue
|
|
135
|
-
request.node.funcargs[argname] = instance
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
anydi/__init__.py,sha256=aeaBp5vq09sG-e9sqqs9qpUtUIDNfOdFPrlAfE5Ku9E,584
|
|
2
|
-
anydi/_container.py,sha256=
|
|
2
|
+
anydi/_container.py,sha256=iVmVlnhK3qfcSCvDZsbD23x2REBtBD26abqKJuLGyHs,29631
|
|
3
3
|
anydi/_context.py,sha256=e0VX0fiflzW_2O9w3HvUH3YRCwXHsruQjf3Lu-zXgDw,10815
|
|
4
4
|
anydi/_logger.py,sha256=UpubJUnW83kffFxkhUlObm2DmZX1Pjqoz9YFKS-JOPg,52
|
|
5
5
|
anydi/_module.py,sha256=E1TfLud_Af-MPB83PxIzHVA1jlDW2FGaRP_il1a6y3Y,3675
|
|
@@ -17,12 +17,12 @@ anydi/ext/django/ninja/__init__.py,sha256=kW3grUgWp_nkWSG_-39ADHMrZLGNcj9TsJ9OW8
|
|
|
17
17
|
anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI8W-oO2w,2696
|
|
18
18
|
anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
|
|
19
19
|
anydi/ext/fastapi.py,sha256=kVUKVKtqCx1Nfnm1oh2BMyB0G7qQKPw6OGfxFlqUqtc,5305
|
|
20
|
-
anydi/ext/pytest_plugin.py,sha256=
|
|
20
|
+
anydi/ext/pytest_plugin.py,sha256=pFLcfxGtJfGSqtk7sPrrHFSKOaZoKZTWt5X8CT0ydmA,4242
|
|
21
21
|
anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
22
|
anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
|
|
23
23
|
anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
-
anydi-0.26.
|
|
25
|
-
anydi-0.26.
|
|
26
|
-
anydi-0.26.
|
|
27
|
-
anydi-0.26.
|
|
28
|
-
anydi-0.26.
|
|
24
|
+
anydi-0.26.2.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
|
|
25
|
+
anydi-0.26.2.dist-info/METADATA,sha256=t-t-Yma46l0AtxjL_qr-RJtMjdqGRVWjLO1VDzULZX4,5160
|
|
26
|
+
anydi-0.26.2.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
27
|
+
anydi-0.26.2.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
|
|
28
|
+
anydi-0.26.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|