anydi 0.25.0a2__tar.gz → 0.25.1__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.25.0a2 → anydi-0.25.1}/PKG-INFO +1 -1
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_container.py +4 -1
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_utils.py +12 -1
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/_settings.py +1 -1
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/_utils.py +4 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/apps.py +5 -2
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/ninja/_signature.py +2 -2
- {anydi-0.25.0a2 → anydi-0.25.1}/pyproject.toml +1 -1
- {anydi-0.25.0a2 → anydi-0.25.1}/LICENSE +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/README.md +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/__init__.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_context.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_logger.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_module.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_scanner.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/_types.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/__init__.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/_container.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/fastapi.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/pytest_plugin.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.25.0a2 → anydi-0.25.1}/anydi/py.typed +0 -0
|
@@ -47,6 +47,7 @@ from ._utils import (
|
|
|
47
47
|
get_full_qualname,
|
|
48
48
|
get_typed_parameters,
|
|
49
49
|
get_typed_return_annotation,
|
|
50
|
+
has_resource_origin,
|
|
50
51
|
is_builtin_type,
|
|
51
52
|
)
|
|
52
53
|
|
|
@@ -723,7 +724,9 @@ class Container:
|
|
|
723
724
|
f"Missing `{get_full_qualname(obj)}` provider return annotation."
|
|
724
725
|
)
|
|
725
726
|
|
|
726
|
-
|
|
727
|
+
origin = get_origin(annotation)
|
|
728
|
+
|
|
729
|
+
if has_resource_origin(origin):
|
|
727
730
|
args = get_args(annotation)
|
|
728
731
|
if args:
|
|
729
732
|
return args[0]
|
|
@@ -6,7 +6,7 @@ import builtins
|
|
|
6
6
|
import functools
|
|
7
7
|
import inspect
|
|
8
8
|
import sys
|
|
9
|
-
from typing import Any, Callable, ForwardRef, TypeVar, cast
|
|
9
|
+
from typing import Any, AsyncIterator, Callable, ForwardRef, Iterator, TypeVar, cast
|
|
10
10
|
|
|
11
11
|
from typing_extensions import Annotated, ParamSpec, get_origin
|
|
12
12
|
|
|
@@ -96,6 +96,17 @@ def get_typed_parameters(obj: Callable[..., Any]) -> list[inspect.Parameter]:
|
|
|
96
96
|
]
|
|
97
97
|
|
|
98
98
|
|
|
99
|
+
_resource_origins = (
|
|
100
|
+
get_origin(Iterator),
|
|
101
|
+
get_origin(AsyncIterator),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def has_resource_origin(origin: Any) -> bool:
|
|
106
|
+
"""Check if the given origin is a resource origin."""
|
|
107
|
+
return origin in _resource_origins
|
|
108
|
+
|
|
109
|
+
|
|
99
110
|
async def run_async(
|
|
100
111
|
func: Callable[P, T],
|
|
101
112
|
/,
|
|
@@ -94,10 +94,14 @@ def inject_urlpatterns(container: anydi.Container, *, urlconf: str) -> None:
|
|
|
94
94
|
"""Auto-inject the container into views."""
|
|
95
95
|
resolver = get_resolver(urlconf)
|
|
96
96
|
for pattern in iter_urlpatterns(resolver.url_patterns):
|
|
97
|
+
# Skip already injected views
|
|
98
|
+
if hasattr(pattern.callback, "_injected"):
|
|
99
|
+
continue
|
|
97
100
|
# Skip django-ninja views
|
|
98
101
|
if pattern.lookup_str.startswith("ninja."):
|
|
99
102
|
continue # pragma: no cover
|
|
100
103
|
pattern.callback = container.inject(pattern.callback)
|
|
104
|
+
pattern.callback._injected = True # type: ignore[attr-defined]
|
|
101
105
|
|
|
102
106
|
|
|
103
107
|
def iter_urlpatterns(
|
|
@@ -33,7 +33,7 @@ class ContainerConfig(AppConfig): # type: ignore[misc]
|
|
|
33
33
|
)
|
|
34
34
|
except ImportError as exc:
|
|
35
35
|
raise ImproperlyConfigured(
|
|
36
|
-
f"Cannot import container
|
|
36
|
+
f"Cannot import container factory '{container_factory_path}'."
|
|
37
37
|
) from exc
|
|
38
38
|
self.container = container_factory()
|
|
39
39
|
else:
|
|
@@ -75,7 +75,10 @@ class ContainerConfig(AppConfig): # type: ignore[misc]
|
|
|
75
75
|
|
|
76
76
|
# Auto-injecting the container into views
|
|
77
77
|
if urlconf := self.settings["INJECT_URLCONF"]:
|
|
78
|
-
|
|
78
|
+
if isinstance(urlconf, str):
|
|
79
|
+
urlconf = [urlconf]
|
|
80
|
+
for u in urlconf:
|
|
81
|
+
inject_urlpatterns(self.container, urlconf=u)
|
|
79
82
|
|
|
80
83
|
# Scan packages
|
|
81
84
|
for scan_package in self.settings["SCAN_PACKAGES"]:
|
|
@@ -11,7 +11,7 @@ from ninja.signature.details import (
|
|
|
11
11
|
)
|
|
12
12
|
from ninja.signature.utils import get_path_param_names, get_typed_signature
|
|
13
13
|
|
|
14
|
-
from anydi._types import
|
|
14
|
+
from anydi._types import is_marker # noqa
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class ViewSignature(BaseViewSignature):
|
|
@@ -46,7 +46,7 @@ class ViewSignature(BaseViewSignature):
|
|
|
46
46
|
continue
|
|
47
47
|
|
|
48
48
|
# Skip default values that are anydi dependency markers
|
|
49
|
-
if
|
|
49
|
+
if is_marker(arg.default):
|
|
50
50
|
self.dependencies.append((name, arg.annotation))
|
|
51
51
|
continue
|
|
52
52
|
|
|
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
|