anydi 0.41.0__py3-none-any.whl → 0.43.0__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/__init__.py +8 -13
- anydi/_async.py +50 -0
- anydi/_container.py +65 -380
- anydi/_context.py +2 -2
- anydi/_decorators.py +122 -0
- anydi/_module.py +77 -0
- anydi/_provider.py +81 -0
- anydi/_scan.py +110 -0
- anydi/_scope.py +9 -0
- anydi/{_utils.py → _typing.py} +49 -69
- anydi/ext/_utils.py +4 -4
- anydi/ext/django/_utils.py +2 -42
- anydi/ext/django/apps.py +0 -3
- anydi/ext/django/ninja/__init__.py +3 -3
- anydi/ext/django/ninja/_operation.py +1 -1
- anydi/ext/django/ninja/_signature.py +1 -1
- anydi/ext/fastapi.py +2 -2
- anydi/ext/faststream.py +2 -2
- anydi/ext/pytest_plugin.py +1 -1
- anydi/ext/starlette/middleware.py +1 -1
- anydi/testing.py +172 -0
- {anydi-0.41.0.dist-info → anydi-0.43.0.dist-info}/METADATA +2 -2
- anydi-0.43.0.dist-info/RECORD +34 -0
- anydi/_types.py +0 -145
- anydi-0.41.0.dist-info/RECORD +0 -28
- {anydi-0.41.0.dist-info → anydi-0.43.0.dist-info}/WHEEL +0 -0
- {anydi-0.41.0.dist-info → anydi-0.43.0.dist-info}/entry_points.txt +0 -0
- {anydi-0.41.0.dist-info → anydi-0.43.0.dist-info}/licenses/LICENSE +0 -0
anydi/__init__.py
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
"""AnyDI public objects and functions."""
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
|
|
5
|
-
from .
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
provider,
|
|
10
|
-
request,
|
|
11
|
-
singleton,
|
|
12
|
-
transient,
|
|
13
|
-
)
|
|
14
|
-
from ._types import Marker, ProviderArgs as Provider, Scope
|
|
3
|
+
from ._container import Container
|
|
4
|
+
from ._decorators import injectable, provided, provider, request, singleton, transient
|
|
5
|
+
from ._module import Module
|
|
6
|
+
from ._provider import ProviderDef as Provider
|
|
7
|
+
from ._scope import Scope
|
|
8
|
+
from ._typing import Marker
|
|
15
9
|
|
|
16
10
|
# Alias for dependency auto marker
|
|
17
|
-
auto =
|
|
11
|
+
auto = Marker()
|
|
18
12
|
|
|
19
13
|
|
|
20
14
|
__all__ = [
|
|
@@ -28,4 +22,5 @@ __all__ = [
|
|
|
28
22
|
"request",
|
|
29
23
|
"singleton",
|
|
30
24
|
"transient",
|
|
25
|
+
"provided",
|
|
31
26
|
]
|
anydi/_async.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
from types import TracebackType
|
|
3
|
+
from typing import Any, Callable, TypeVar
|
|
4
|
+
|
|
5
|
+
import anyio.to_thread
|
|
6
|
+
from typing_extensions import ParamSpec, Self
|
|
7
|
+
|
|
8
|
+
T = TypeVar("T")
|
|
9
|
+
P = ParamSpec("P")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def run_sync(func: Callable[P, T], /, *args: P.args, **kwargs: P.kwargs) -> T:
|
|
13
|
+
"""Runs the given function asynchronously using the `anyio` library."""
|
|
14
|
+
return await anyio.to_thread.run_sync(functools.partial(func, *args, **kwargs))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class AsyncRLock:
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
self._lock = anyio.Lock()
|
|
20
|
+
self._owner: anyio.TaskInfo | None = None
|
|
21
|
+
self._count = 0
|
|
22
|
+
|
|
23
|
+
async def acquire(self) -> None:
|
|
24
|
+
current_task = anyio.get_current_task()
|
|
25
|
+
if self._owner == current_task:
|
|
26
|
+
self._count += 1
|
|
27
|
+
else:
|
|
28
|
+
await self._lock.acquire()
|
|
29
|
+
self._owner = current_task
|
|
30
|
+
self._count = 1
|
|
31
|
+
|
|
32
|
+
def release(self) -> None:
|
|
33
|
+
if self._owner != anyio.get_current_task():
|
|
34
|
+
raise RuntimeError("Lock can only be released by the owner")
|
|
35
|
+
self._count -= 1
|
|
36
|
+
if self._count == 0:
|
|
37
|
+
self._owner = None
|
|
38
|
+
self._lock.release()
|
|
39
|
+
|
|
40
|
+
async def __aenter__(self) -> Self:
|
|
41
|
+
await self.acquire()
|
|
42
|
+
return self
|
|
43
|
+
|
|
44
|
+
async def __aexit__(
|
|
45
|
+
self,
|
|
46
|
+
exc_type: type[BaseException] | None,
|
|
47
|
+
exc_val: BaseException | None,
|
|
48
|
+
exc_tb: TracebackType | None,
|
|
49
|
+
) -> Any:
|
|
50
|
+
self.release()
|