anydi 0.67.1__py3-none-any.whl → 0.67.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 +14 -19
- anydi/ext/typer.py +3 -3
- {anydi-0.67.1.dist-info → anydi-0.67.2.dist-info}/METADATA +1 -1
- {anydi-0.67.1.dist-info → anydi-0.67.2.dist-info}/RECORD +6 -6
- {anydi-0.67.1.dist-info → anydi-0.67.2.dist-info}/WHEEL +0 -0
- {anydi-0.67.1.dist-info → anydi-0.67.2.dist-info}/entry_points.txt +0 -0
anydi/_container.py
CHANGED
|
@@ -23,14 +23,7 @@ from ._module import ModuleDef, ModuleRegistrar
|
|
|
23
23
|
from ._provider import Provider, ProviderDef, ProviderKind, ProviderParameter
|
|
24
24
|
from ._resolver import Resolver
|
|
25
25
|
from ._scanner import PackageOrIterable, Scanner
|
|
26
|
-
from ._types import
|
|
27
|
-
NOT_SET,
|
|
28
|
-
Event,
|
|
29
|
-
Scope,
|
|
30
|
-
is_event_type,
|
|
31
|
-
is_iterator_type,
|
|
32
|
-
is_none_type,
|
|
33
|
-
)
|
|
26
|
+
from ._types import NOT_SET, Event, Scope, is_event_type, is_iterator_type, is_none_type
|
|
34
27
|
|
|
35
28
|
T = TypeVar("T", bound=Any)
|
|
36
29
|
P = ParamSpec("P")
|
|
@@ -437,7 +430,9 @@ class Container:
|
|
|
437
430
|
scope_hierarchy = self._scopes.get(scope, ()) if scope != "transient" else ()
|
|
438
431
|
|
|
439
432
|
for parameter in signature.parameters.values():
|
|
440
|
-
|
|
433
|
+
annotation = parameter.annotation
|
|
434
|
+
|
|
435
|
+
if annotation is inspect.Parameter.empty:
|
|
441
436
|
raise TypeError(
|
|
442
437
|
f"Missing provider `{name}` "
|
|
443
438
|
f"dependency `{parameter.name}` annotation."
|
|
@@ -452,17 +447,17 @@ class Container:
|
|
|
452
447
|
default = parameter.default if has_default else NOT_SET
|
|
453
448
|
|
|
454
449
|
try:
|
|
455
|
-
sub_provider = self._get_or_register_provider(
|
|
450
|
+
sub_provider = self._get_or_register_provider(annotation)
|
|
456
451
|
except LookupError as exc:
|
|
457
452
|
if (defaults and parameter.name in defaults) or has_default:
|
|
458
453
|
continue
|
|
459
454
|
# For scoped dependencies, allow unresolved parameters via context.set()
|
|
460
455
|
if is_scoped:
|
|
461
|
-
self._resolver.add_unresolved(
|
|
456
|
+
self._resolver.add_unresolved(annotation)
|
|
462
457
|
parameters.append(
|
|
463
458
|
ProviderParameter(
|
|
464
459
|
name=parameter.name,
|
|
465
|
-
annotation=
|
|
460
|
+
annotation=annotation,
|
|
466
461
|
default=default,
|
|
467
462
|
has_default=has_default,
|
|
468
463
|
provider=None,
|
|
@@ -484,11 +479,11 @@ class Container:
|
|
|
484
479
|
and sub_provider.scope == scope
|
|
485
480
|
and any(p.provider is None for p in sub_provider.parameters)
|
|
486
481
|
):
|
|
487
|
-
self._resolver.add_unresolved(
|
|
482
|
+
self._resolver.add_unresolved(annotation)
|
|
488
483
|
parameters.append(
|
|
489
484
|
ProviderParameter(
|
|
490
485
|
name=parameter.name,
|
|
491
|
-
annotation=
|
|
486
|
+
annotation=annotation,
|
|
492
487
|
default=default,
|
|
493
488
|
has_default=has_default,
|
|
494
489
|
provider=None,
|
|
@@ -509,7 +504,7 @@ class Container:
|
|
|
509
504
|
parameters.append(
|
|
510
505
|
ProviderParameter(
|
|
511
506
|
name=parameter.name,
|
|
512
|
-
annotation=
|
|
507
|
+
annotation=annotation,
|
|
513
508
|
default=default,
|
|
514
509
|
has_default=has_default,
|
|
515
510
|
provider=sub_provider,
|
|
@@ -574,20 +569,20 @@ class Container:
|
|
|
574
569
|
"""Get provider by interface."""
|
|
575
570
|
try:
|
|
576
571
|
return self._providers[interface]
|
|
577
|
-
except KeyError
|
|
572
|
+
except KeyError:
|
|
578
573
|
raise LookupError(
|
|
579
574
|
f"The provider interface for `{type_repr(interface)}` has "
|
|
580
575
|
"not been registered. Please ensure that the provider interface is "
|
|
581
576
|
"properly registered before attempting to use it."
|
|
582
|
-
) from
|
|
577
|
+
) from None
|
|
583
578
|
|
|
584
579
|
def _get_or_register_provider(
|
|
585
580
|
self, interface: Any, defaults: dict[str, Any] | None = None
|
|
586
581
|
) -> Provider:
|
|
587
582
|
"""Get or register a provider by interface."""
|
|
588
583
|
try:
|
|
589
|
-
return self.
|
|
590
|
-
except
|
|
584
|
+
return self._get_provider(interface)
|
|
585
|
+
except LookupError:
|
|
591
586
|
if inspect.isclass(interface) and is_provided(interface):
|
|
592
587
|
return self._register_provider(
|
|
593
588
|
interface,
|
anydi/ext/typer.py
CHANGED
|
@@ -42,7 +42,7 @@ def _wrap_async_callback_with_injection(
|
|
|
42
42
|
callback: Callable[..., Awaitable[Any]],
|
|
43
43
|
container: Container,
|
|
44
44
|
sig: inspect.Signature,
|
|
45
|
-
non_injected_params:
|
|
45
|
+
non_injected_params: list[inspect.Parameter],
|
|
46
46
|
scopes: set[Scope],
|
|
47
47
|
) -> Any:
|
|
48
48
|
"""Wrap async callback with injection in anyio.run()."""
|
|
@@ -86,7 +86,7 @@ def _process_callback(callback: Callable[..., Any], container: Container) -> Any
|
|
|
86
86
|
"""Validate and wrap a callback for dependency injection."""
|
|
87
87
|
sig = inspect.signature(callback, eval_str=True)
|
|
88
88
|
injected_param_names: set[str] = set()
|
|
89
|
-
non_injected_params:
|
|
89
|
+
non_injected_params: list[inspect.Parameter] = []
|
|
90
90
|
scopes: set[Scope] = set()
|
|
91
91
|
|
|
92
92
|
# Validate parameters and collect which ones need injection
|
|
@@ -103,7 +103,7 @@ def _process_callback(callback: Callable[..., Any], container: Container) -> Any
|
|
|
103
103
|
if inspect.isclass(interface) and is_provided(interface):
|
|
104
104
|
scopes.add(interface.__provided__["scope"])
|
|
105
105
|
else:
|
|
106
|
-
non_injected_params.
|
|
106
|
+
non_injected_params.append(processed_parameter)
|
|
107
107
|
|
|
108
108
|
# If no parameters need injection and callback is not async, return original
|
|
109
109
|
if not injected_param_names and not inspect.iscoroutinefunction(callback):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
anydi/__init__.py,sha256=KFX8OthKXwBuYDPCV61t-044DpJ88tAOzIxeUWRC5OA,633
|
|
2
2
|
anydi/_async_lock.py,sha256=3dwZr0KthXFYha0XKMyXf8jMmGb1lYoNC0O5w29V9ic,1104
|
|
3
|
-
anydi/_container.py,sha256=
|
|
3
|
+
anydi/_container.py,sha256=e73sTDIkE9Cn0DWgYc-Y-xnAUC7kCWCpc28jCiozqz0,29356
|
|
4
4
|
anydi/_context.py,sha256=-9QqeMWo9OpZVXZxZCQgIsswggl3Ch7lgx1KiFX_ezc,3752
|
|
5
5
|
anydi/_decorators.py,sha256=J3W261ZAG7q4XKm4tbAv1wsWr9ysx9_5MUbUvSJB_MQ,2809
|
|
6
6
|
anydi/_injector.py,sha256=1Ux71DhGxu3dLwPJP8gU73olI0pcZ3_tVaVzwKH7100,4411
|
|
@@ -18,10 +18,10 @@ anydi/ext/pydantic_settings.py,sha256=jVJZ1wPaPpsxdNPlJj9yq282ebqLZ9tckWpZ0eIwWL
|
|
|
18
18
|
anydi/ext/pytest_plugin.py,sha256=M54DkA-KxD9GqLnXdoCyn-Qur2c44MB6d0AgJuYCZ5w,16171
|
|
19
19
|
anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
20
20
|
anydi/ext/starlette/middleware.py,sha256=n_JJ7BcG2Mg2M5HwM_SBboxZ-mnnD6WWJn4khq7Bgbs,1860
|
|
21
|
-
anydi/ext/typer.py,sha256=
|
|
21
|
+
anydi/ext/typer.py,sha256=cCkERh70RYWGuESE4nFwjDrzLAMztVLGgGeUBWLAjEQ,6238
|
|
22
22
|
anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
23
23
|
anydi/testing.py,sha256=cHg3mMScZbEep9smRqSNQ81BZMQOkyugHe8TvKdPnEg,1347
|
|
24
|
-
anydi-0.67.
|
|
25
|
-
anydi-0.67.
|
|
26
|
-
anydi-0.67.
|
|
27
|
-
anydi-0.67.
|
|
24
|
+
anydi-0.67.2.dist-info/WHEEL,sha256=eh7sammvW2TypMMMGKgsM83HyA_3qQ5Lgg3ynoecH3M,79
|
|
25
|
+
anydi-0.67.2.dist-info/entry_points.txt,sha256=AgOcQYM5KyS4D37QcYb00tiid0QA-pD1VrjHHq4QAps,44
|
|
26
|
+
anydi-0.67.2.dist-info/METADATA,sha256=-RMwk-7ZbR7MJLY11pKe40CzhIF9w1NznfHj6GK6mug,8061
|
|
27
|
+
anydi-0.67.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|