anydi 0.36.1a4__tar.gz → 0.37.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.
- {anydi-0.36.1a4 → anydi-0.37.0}/PKG-INFO +1 -1
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/_container.py +11 -6
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/_provider.py +7 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/pyproject.toml +1 -1
- {anydi-0.36.1a4 → anydi-0.37.0}/LICENSE +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/README.md +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/__init__.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/_context.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/_types.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/_utils.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/__init__.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/_utils.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/_container.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/_settings.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/_utils.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/apps.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/django/ninja/_signature.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/fastapi.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/faststream.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/pydantic_settings.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/pytest_plugin.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.36.1a4 → anydi-0.37.0}/anydi/py.typed +0 -0
|
@@ -556,7 +556,7 @@ class Container:
|
|
|
556
556
|
return context.enter(cm)
|
|
557
557
|
|
|
558
558
|
instance = provider.call(**provider_kwargs)
|
|
559
|
-
if context is not None and is_context_manager(instance):
|
|
559
|
+
if context is not None and provider.is_class and is_context_manager(instance):
|
|
560
560
|
context.enter(instance)
|
|
561
561
|
return instance
|
|
562
562
|
|
|
@@ -569,10 +569,7 @@ class Container:
|
|
|
569
569
|
)
|
|
570
570
|
|
|
571
571
|
if provider.is_coroutine:
|
|
572
|
-
|
|
573
|
-
if context is not None and is_async_context_manager(instance):
|
|
574
|
-
await context.aenter(instance)
|
|
575
|
-
return instance
|
|
572
|
+
return await provider.call(**provider_kwargs)
|
|
576
573
|
|
|
577
574
|
if provider.is_async_generator:
|
|
578
575
|
if context is None:
|
|
@@ -593,7 +590,11 @@ class Container:
|
|
|
593
590
|
return await run_async(_create)
|
|
594
591
|
|
|
595
592
|
instance = await run_async(provider.call, **provider_kwargs)
|
|
596
|
-
if
|
|
593
|
+
if (
|
|
594
|
+
context is not None
|
|
595
|
+
and provider.is_class
|
|
596
|
+
and is_async_context_manager(instance)
|
|
597
|
+
):
|
|
597
598
|
await context.aenter(instance)
|
|
598
599
|
return instance
|
|
599
600
|
|
|
@@ -787,6 +788,10 @@ class Container:
|
|
|
787
788
|
"""
|
|
788
789
|
Override the provider for the specified interface with a specific instance.
|
|
789
790
|
"""
|
|
791
|
+
if not self.testing:
|
|
792
|
+
raise RuntimeError(
|
|
793
|
+
"The `override` method can only be used in testing mode."
|
|
794
|
+
)
|
|
790
795
|
if not self.is_registered(interface) and self.strict:
|
|
791
796
|
raise LookupError(
|
|
792
797
|
f"The provider interface `{get_full_qualname(interface)}` "
|
|
@@ -38,6 +38,7 @@ class Provider:
|
|
|
38
38
|
"_kind",
|
|
39
39
|
"_interface",
|
|
40
40
|
"_parameters",
|
|
41
|
+
"_is_class",
|
|
41
42
|
"_is_coroutine",
|
|
42
43
|
"_is_generator",
|
|
43
44
|
"_is_async_generator",
|
|
@@ -57,6 +58,7 @@ class Provider:
|
|
|
57
58
|
# Detect the kind of callable provider
|
|
58
59
|
self._detect_kind()
|
|
59
60
|
|
|
61
|
+
self._is_class = self._kind == CallableKind.CLASS
|
|
60
62
|
self._is_coroutine = self._kind == CallableKind.COROUTINE
|
|
61
63
|
self._is_generator = self._kind == CallableKind.GENERATOR
|
|
62
64
|
self._is_async_generator = self._kind == CallableKind.ASYNC_GENERATOR
|
|
@@ -107,6 +109,11 @@ class Provider:
|
|
|
107
109
|
def parameters(self) -> list[inspect.Parameter]:
|
|
108
110
|
return self._parameters
|
|
109
111
|
|
|
112
|
+
@property
|
|
113
|
+
def is_class(self) -> bool:
|
|
114
|
+
"""Check if the provider is a class."""
|
|
115
|
+
return self._is_class
|
|
116
|
+
|
|
110
117
|
@property
|
|
111
118
|
def is_coroutine(self) -> bool:
|
|
112
119
|
"""Check if the provider is a coroutine."""
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|