anydi 0.27.0a8__tar.gz → 0.28.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.27.0a8 → anydi-0.28.0}/PKG-INFO +2 -3
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_container.py +4 -4
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_context.py +24 -9
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_utils.py +12 -15
- {anydi-0.27.0a8 → anydi-0.28.0}/pyproject.toml +6 -7
- {anydi-0.27.0a8 → anydi-0.28.0}/LICENSE +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/README.md +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/__init__.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_logger.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_module.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_scanner.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/_types.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/__init__.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/_utils.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/_container.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/_settings.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/_utils.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/apps.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/django/ninja/_signature.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/fastapi.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/faststream.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/pytest_plugin.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.27.0a8 → anydi-0.28.0}/anydi/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: anydi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.28.0
|
|
4
4
|
Summary: Dependency Injection library
|
|
5
5
|
Home-page: https://github.com/antonrh/anydi
|
|
6
6
|
License: MIT
|
|
@@ -22,7 +22,6 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
22
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
24
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
25
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
26
25
|
Classifier: Topic :: Internet
|
|
27
26
|
Classifier: Topic :: Software Development
|
|
28
27
|
Classifier: Topic :: Software Development :: Libraries
|
|
@@ -33,7 +32,7 @@ Provides-Extra: async
|
|
|
33
32
|
Provides-Extra: docs
|
|
34
33
|
Requires-Dist: anyio (>=3.6.2,<4.0.0) ; extra == "async"
|
|
35
34
|
Requires-Dist: mkdocs (>=1.4.2,<2.0.0) ; extra == "docs"
|
|
36
|
-
Requires-Dist: mkdocs-material (>=9.5.
|
|
35
|
+
Requires-Dist: mkdocs-material (>=9.5.29,<10.0.0) ; extra == "docs"
|
|
37
36
|
Requires-Dist: typing-extensions (>=4.12.1,<5.0.0)
|
|
38
37
|
Project-URL: Repository, https://github.com/antonrh/anydi
|
|
39
38
|
Description-Content-Type: text/markdown
|
|
@@ -429,9 +429,9 @@ class Container:
|
|
|
429
429
|
exc_type: type[BaseException] | None,
|
|
430
430
|
exc_val: BaseException | None,
|
|
431
431
|
exc_tb: types.TracebackType | None,
|
|
432
|
-
) ->
|
|
432
|
+
) -> bool:
|
|
433
433
|
"""Exit the singleton context."""
|
|
434
|
-
self.
|
|
434
|
+
return self._singleton_context.__exit__(exc_type, exc_val, exc_tb)
|
|
435
435
|
|
|
436
436
|
def start(self) -> None:
|
|
437
437
|
"""Start the singleton context."""
|
|
@@ -464,9 +464,9 @@ class Container:
|
|
|
464
464
|
exc_type: type[BaseException] | None,
|
|
465
465
|
exc_val: BaseException | None,
|
|
466
466
|
exc_tb: types.TracebackType | None,
|
|
467
|
-
) ->
|
|
467
|
+
) -> bool:
|
|
468
468
|
"""Exit the singleton context."""
|
|
469
|
-
await self.
|
|
469
|
+
return await self._singleton_context.__aexit__(exc_type, exc_val, exc_tb)
|
|
470
470
|
|
|
471
471
|
async def astart(self) -> None:
|
|
472
472
|
"""Start the singleton context asynchronously."""
|
|
@@ -195,6 +195,14 @@ class ResourceScopedContext(ScopedContext):
|
|
|
195
195
|
"""
|
|
196
196
|
return interface in self._instances
|
|
197
197
|
|
|
198
|
+
def _create_instance(self, provider: Provider) -> Any:
|
|
199
|
+
"""Create an instance using the provider."""
|
|
200
|
+
instance = super()._create_instance(provider)
|
|
201
|
+
# Enter the context manager if the instance is closable.
|
|
202
|
+
if hasattr(instance, "__enter__") and hasattr(instance, "__exit__"):
|
|
203
|
+
self._stack.enter_context(instance)
|
|
204
|
+
return instance
|
|
205
|
+
|
|
198
206
|
def _create_resource(self, provider: Provider) -> Any:
|
|
199
207
|
"""Create a resource using the provider.
|
|
200
208
|
|
|
@@ -208,6 +216,14 @@ class ResourceScopedContext(ScopedContext):
|
|
|
208
216
|
cm = contextlib.contextmanager(provider.obj)(*args, **kwargs)
|
|
209
217
|
return self._stack.enter_context(cm)
|
|
210
218
|
|
|
219
|
+
async def _acreate_instance(self, provider: Provider) -> Any:
|
|
220
|
+
"""Create an instance asynchronously using the provider."""
|
|
221
|
+
instance = await super()._acreate_instance(provider)
|
|
222
|
+
# Enter the context manager if the instance is closable.
|
|
223
|
+
if hasattr(instance, "__aenter__") and hasattr(instance, "__aexit__"):
|
|
224
|
+
await self._async_stack.enter_async_context(instance)
|
|
225
|
+
return instance
|
|
226
|
+
|
|
211
227
|
async def _acreate_resource(self, provider: Provider) -> Any:
|
|
212
228
|
"""Create a resource asynchronously using the provider.
|
|
213
229
|
|
|
@@ -243,7 +259,7 @@ class ResourceScopedContext(ScopedContext):
|
|
|
243
259
|
exc_type: type[BaseException] | None,
|
|
244
260
|
exc_val: BaseException | None,
|
|
245
261
|
exc_tb: TracebackType | None,
|
|
246
|
-
) ->
|
|
262
|
+
) -> bool:
|
|
247
263
|
"""Exit the context.
|
|
248
264
|
|
|
249
265
|
Args:
|
|
@@ -251,8 +267,7 @@ class ResourceScopedContext(ScopedContext):
|
|
|
251
267
|
exc_val: The exception instance, if any.
|
|
252
268
|
exc_tb: The traceback, if any.
|
|
253
269
|
"""
|
|
254
|
-
self.
|
|
255
|
-
return
|
|
270
|
+
return self._stack.__exit__(exc_type, exc_val, exc_tb) # type: ignore[return-value]
|
|
256
271
|
|
|
257
272
|
@abc.abstractmethod
|
|
258
273
|
def start(self) -> None:
|
|
@@ -262,7 +277,7 @@ class ResourceScopedContext(ScopedContext):
|
|
|
262
277
|
|
|
263
278
|
def close(self) -> None:
|
|
264
279
|
"""Close the scoped context."""
|
|
265
|
-
self._stack.
|
|
280
|
+
self._stack.__exit__(None, None, None)
|
|
266
281
|
|
|
267
282
|
async def __aenter__(self) -> Self:
|
|
268
283
|
"""Enter the context asynchronously.
|
|
@@ -278,7 +293,7 @@ class ResourceScopedContext(ScopedContext):
|
|
|
278
293
|
exc_type: type[BaseException] | None,
|
|
279
294
|
exc_val: BaseException | None,
|
|
280
295
|
exc_tb: TracebackType | None,
|
|
281
|
-
) ->
|
|
296
|
+
) -> bool:
|
|
282
297
|
"""Exit the context asynchronously.
|
|
283
298
|
|
|
284
299
|
Args:
|
|
@@ -286,8 +301,9 @@ class ResourceScopedContext(ScopedContext):
|
|
|
286
301
|
exc_val: The exception instance, if any.
|
|
287
302
|
exc_tb: The traceback, if any.
|
|
288
303
|
"""
|
|
289
|
-
await
|
|
290
|
-
|
|
304
|
+
return await run_async(
|
|
305
|
+
self.__exit__, exc_type, exc_val, exc_tb
|
|
306
|
+
) or await self._async_stack.__aexit__(exc_type, exc_val, exc_tb)
|
|
291
307
|
|
|
292
308
|
@abc.abstractmethod
|
|
293
309
|
async def astart(self) -> None:
|
|
@@ -295,8 +311,7 @@ class ResourceScopedContext(ScopedContext):
|
|
|
295
311
|
|
|
296
312
|
async def aclose(self) -> None:
|
|
297
313
|
"""Close the scoped context asynchronously."""
|
|
298
|
-
await
|
|
299
|
-
await self._async_stack.aclose()
|
|
314
|
+
await self.__aexit__(None, None, None)
|
|
300
315
|
|
|
301
316
|
|
|
302
317
|
@final
|
|
@@ -6,7 +6,7 @@ import builtins
|
|
|
6
6
|
import functools
|
|
7
7
|
import inspect
|
|
8
8
|
import sys
|
|
9
|
-
from typing import Any, AsyncIterator, Callable, ForwardRef, Iterator, TypeVar
|
|
9
|
+
from typing import Any, AsyncIterator, Callable, ForwardRef, Iterator, TypeVar
|
|
10
10
|
|
|
11
11
|
from typing_extensions import ParamSpec, get_args, get_origin
|
|
12
12
|
|
|
@@ -16,17 +16,6 @@ except ImportError:
|
|
|
16
16
|
anyio = None # type: ignore[assignment]
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
if sys.version_info < (3, 9): # pragma: nocover
|
|
20
|
-
|
|
21
|
-
def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
|
|
22
|
-
return type_._evaluate(globalns, localns) # noqa
|
|
23
|
-
|
|
24
|
-
else:
|
|
25
|
-
|
|
26
|
-
def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
|
|
27
|
-
return cast(Any, type_)._evaluate(globalns, localns, set()) # noqa
|
|
28
|
-
|
|
29
|
-
|
|
30
19
|
T = TypeVar("T")
|
|
31
20
|
P = ParamSpec("P")
|
|
32
21
|
|
|
@@ -62,6 +51,12 @@ def is_builtin_type(tp: type[Any]) -> bool:
|
|
|
62
51
|
return tp.__module__ == builtins.__name__
|
|
63
52
|
|
|
64
53
|
|
|
54
|
+
def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any:
|
|
55
|
+
if sys.version_info < (3, 9):
|
|
56
|
+
return type_._evaluate(globalns, localns)
|
|
57
|
+
return type_._evaluate(globalns, localns, recursive_guard=frozenset())
|
|
58
|
+
|
|
59
|
+
|
|
65
60
|
def get_typed_annotation(
|
|
66
61
|
annotation: Any,
|
|
67
62
|
globalns: dict[str, Any],
|
|
@@ -70,10 +65,12 @@ def get_typed_annotation(
|
|
|
70
65
|
) -> Any:
|
|
71
66
|
"""Get the typed annotation of a parameter."""
|
|
72
67
|
if isinstance(annotation, str):
|
|
73
|
-
if sys.version_info
|
|
74
|
-
annotation = ForwardRef(annotation)
|
|
75
|
-
else:
|
|
68
|
+
if sys.version_info >= (3, 10, 2):
|
|
76
69
|
annotation = ForwardRef(annotation, module=module, is_class=is_class)
|
|
70
|
+
elif sys.version_info >= (3, 10, 0):
|
|
71
|
+
annotation = ForwardRef(annotation, module=module)
|
|
72
|
+
else:
|
|
73
|
+
annotation = ForwardRef(annotation)
|
|
77
74
|
annotation = evaluate_forwardref(annotation, globalns, {})
|
|
78
75
|
return annotation
|
|
79
76
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "anydi"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.28.0"
|
|
4
4
|
description = "Dependency Injection library"
|
|
5
5
|
authors = ["Anton Ruhlov <antonruhlov@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -22,7 +22,6 @@ classifiers = [
|
|
|
22
22
|
"Intended Audience :: Developers",
|
|
23
23
|
"License :: OSI Approved :: MIT License",
|
|
24
24
|
"Programming Language :: Python :: 3",
|
|
25
|
-
"Programming Language :: Python :: 3.7",
|
|
26
25
|
"Programming Language :: Python :: 3.8",
|
|
27
26
|
"Programming Language :: Python :: 3.9",
|
|
28
27
|
"Programming Language :: Python :: 3.10",
|
|
@@ -39,16 +38,16 @@ python = "^3.8"
|
|
|
39
38
|
typing-extensions = "^4.12.1"
|
|
40
39
|
anyio = { version = "^3.6.2", optional = true }
|
|
41
40
|
mkdocs = { version = "^1.4.2", optional = true }
|
|
42
|
-
mkdocs-material = { version = "^9.5.
|
|
41
|
+
mkdocs-material = { version = "^9.5.29", optional = true }
|
|
43
42
|
|
|
44
43
|
[tool.poetry.extras]
|
|
45
44
|
docs = ["mkdocs", "mkdocs-material"]
|
|
46
45
|
async = ["anyio"]
|
|
47
46
|
|
|
48
47
|
[tool.poetry.group.dev.dependencies]
|
|
49
|
-
mypy = "^1.
|
|
50
|
-
ruff = "^0.
|
|
51
|
-
pytest = "^8.1
|
|
48
|
+
mypy = "^1.11.1"
|
|
49
|
+
ruff = "^0.6.1"
|
|
50
|
+
pytest = "^8.3.1"
|
|
52
51
|
pytest-cov = "^5.0.0"
|
|
53
52
|
fastapi = "^0.100.0"
|
|
54
53
|
httpx = "^0.26.0"
|
|
@@ -65,7 +64,7 @@ anydi = "anydi.ext.pytest_plugin"
|
|
|
65
64
|
line-length = 88
|
|
66
65
|
|
|
67
66
|
[tool.ruff.lint]
|
|
68
|
-
select = ["A", "B", "C", "E", "F", "I", "W", "TID252", "T20", "UP"]
|
|
67
|
+
select = ["A", "B", "C", "E", "F", "I", "W", "TID252", "T20", "UP", "FURB"]
|
|
69
68
|
ignore = ["A003", "B008", "B009", "B010", "D104", "D107"]
|
|
70
69
|
|
|
71
70
|
[tool.ruff.lint.isort]
|
|
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
|