anydi 0.30.0__py3-none-any.whl → 0.32.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.
@@ -1,26 +1,28 @@
1
- from typing import Callable
1
+ from typing import Any, Callable
2
2
 
3
3
  from asgiref.sync import iscoroutinefunction
4
- from django.http import HttpRequest, HttpResponse
4
+ from django.http import HttpRequest
5
5
  from django.utils.decorators import sync_and_async_middleware
6
6
 
7
7
  from ._container import container
8
8
 
9
9
 
10
- @sync_and_async_middleware # type: ignore[misc]
10
+ @sync_and_async_middleware
11
11
  def request_scoped_middleware(
12
- get_response: Callable[[HttpRequest], HttpResponse],
13
- ) -> Callable[[HttpRequest], HttpResponse]:
12
+ get_response: Callable[..., Any],
13
+ ) -> Callable[..., Any]:
14
14
  if iscoroutinefunction(get_response):
15
15
 
16
- async def async_middleware(request: HttpRequest) -> HttpResponse:
17
- async with container.arequest_context():
16
+ async def async_middleware(request: HttpRequest) -> Any:
17
+ async with container.arequest_context() as ctx:
18
+ ctx.set(HttpRequest, instance=request)
18
19
  return await get_response(request)
19
20
 
20
21
  return async_middleware
21
22
 
22
- def middleware(request: HttpRequest) -> HttpResponse:
23
- with container.request_context():
23
+ def middleware(request: HttpRequest) -> Any:
24
+ with container.request_context() as ctx:
25
+ ctx.set(HttpRequest, instance=request)
24
26
  return get_response(request)
25
27
 
26
28
  return middleware
anydi/ext/fastapi.py CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import logging
6
- from typing import Any, Iterator, cast
5
+ from collections.abc import Iterator
6
+ from typing import Any, cast
7
7
 
8
8
  from fastapi import Depends, FastAPI, params
9
9
  from fastapi.dependencies.models import Dependant
@@ -18,16 +18,10 @@ from .starlette.middleware import RequestScopedMiddleware
18
18
 
19
19
  __all__ = ["RequestScopedMiddleware", "install", "get_container", "Inject"]
20
20
 
21
- logger = logging.getLogger(__name__)
22
-
23
21
 
24
22
  def install(app: FastAPI, container: Container) -> None:
25
23
  """Install AnyDI into a FastAPI application.
26
24
 
27
- Args:
28
- app: The FastAPI application instance.
29
- container: The container.
30
-
31
25
  This function installs the AnyDI container into a FastAPI application by attaching
32
26
  it to the application state. It also patches the route dependencies to inject the
33
27
  required dependencies using AnyDI.
@@ -51,14 +45,7 @@ def install(app: FastAPI, container: Container) -> None:
51
45
 
52
46
 
53
47
  def get_container(request: Request) -> Container:
54
- """Get the AnyDI container from a FastAPI request.
55
-
56
- Args:
57
- request: The FastAPI request.
58
-
59
- Returns:
60
- The AnyDI container associated with the request.
61
- """
48
+ """Get the AnyDI container from a FastAPI request."""
62
49
  return cast(Container, request.app.state.container)
63
50
 
64
51
 
@@ -73,14 +60,7 @@ class Resolver(HasInterface, params.Depends):
73
60
 
74
61
 
75
62
  def Inject() -> Any: # noqa
76
- """Decorator for marking a function parameter as requiring injection.
77
-
78
- The `Inject` decorator is used to mark a function parameter as requiring injection
79
- of a dependency resolved by AnyDI.
80
-
81
- Returns:
82
- The `Resolver` instance representing the parameter dependency.
83
- """
63
+ """Decorator for marking a function parameter as requiring injection."""
84
64
  return Resolver()
85
65
 
86
66
 
anydi/ext/faststream.py CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- import logging
6
5
  from typing import Any, cast
7
6
 
8
7
  from fast_depends.dependencies import Depends
@@ -14,16 +13,10 @@ from anydi._utils import get_typed_parameters
14
13
 
15
14
  from ._utils import HasInterface, patch_call_parameter
16
15
 
17
- logger = logging.getLogger(__name__)
18
-
19
16
 
20
17
  def install(broker: BrokerUsecase[Any, Any], container: Container) -> None:
21
18
  """Install AnyDI into a FastStream broker.
22
19
 
23
- Args:
24
- broker: The broker.
25
- container: The container.
26
-
27
20
  This function installs the AnyDI container into a FastStream broker by attaching
28
21
  it to the broker. It also patches the broker handlers to inject the required
29
22
  dependencies using AnyDI.
@@ -1,10 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Any, Callable, Iterable
3
+ from collections.abc import Iterable
4
+ from typing import Annotated, Any, Callable
4
5
 
5
6
  from pydantic.fields import ComputedFieldInfo, FieldInfo # noqa
6
7
  from pydantic_settings import BaseSettings
7
- from typing_extensions import Annotated
8
8
 
9
9
  from anydi import Container
10
10
 
@@ -1,13 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import inspect
4
- from typing import Any, Callable, Iterator, cast
4
+ import logging
5
+ from collections.abc import Iterator
6
+ from typing import Any, Callable, cast
5
7
 
6
8
  import pytest
7
9
 
8
10
  from anydi import Container
9
11
  from anydi._utils import get_typed_parameters
10
12
 
13
+ logger = logging.getLogger(__name__)
14
+
11
15
 
12
16
  def pytest_configure(config: pytest.Config) -> None:
13
17
  config.addinivalue_line(
@@ -69,7 +73,7 @@ def _anydi_injected_parameter_iterator(
69
73
  for parameter in get_typed_parameters(request.function):
70
74
  interface = parameter.annotation
71
75
  if (
72
- interface is parameter.empty
76
+ interface is inspect.Parameter.empty
73
77
  or interface in _anydi_unresolved
74
78
  or parameter.name in registered_fixtures
75
79
  ):
@@ -102,6 +106,7 @@ def _anydi_inject(
102
106
  try:
103
107
  request.node.funcargs[argname] = container.resolve(interface)
104
108
  except Exception: # noqa
109
+ logger.warning(f"Failed to resolve dependency for argument '{argname}'.")
105
110
  _anydi_unresolved.append(interface)
106
111
 
107
112
 
@@ -127,4 +132,5 @@ async def _anydi_ainject(
127
132
  try:
128
133
  request.node.funcargs[argname] = await container.aresolve(interface)
129
134
  except Exception: # noqa
135
+ logger.warning(f"Failed to resolve dependency for argument '{argname}'.")
130
136
  _anydi_unresolved.append(interface)
@@ -12,26 +12,12 @@ class RequestScopedMiddleware(BaseHTTPMiddleware):
12
12
  """Starlette middleware for managing request-scoped AnyDI context."""
13
13
 
14
14
  def __init__(self, app: ASGIApp, container: Container) -> None:
15
- """Initialize the RequestScopedMiddleware.
16
-
17
- Args:
18
- app: The ASGI application.
19
- container: The container.
20
- """
21
15
  super().__init__(app)
22
16
  self.container = container
23
17
 
24
18
  async def dispatch(
25
19
  self, request: Request, call_next: RequestResponseEndpoint
26
20
  ) -> Response:
27
- """Dispatch the request and handle the response.
28
-
29
- Args:
30
- request: The incoming request.
31
- call_next: The next request-response endpoint.
32
-
33
- Returns:
34
- The response to the request.
35
- """
36
- async with self.container.arequest_context():
21
+ async with self.container.arequest_context() as ctx:
22
+ ctx.set(Request, instance=request)
37
23
  return await call_next(request)
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.30.0
3
+ Version: 0.32.0
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
7
7
  Keywords: dependency injection,dependencies,di,async,asyncio,application
8
8
  Author: Anton Ruhlov
9
9
  Author-email: antonruhlov@gmail.com
10
- Requires-Python: >=3.8,<4.0
10
+ Requires-Python: >=3.9,<4.0
11
11
  Classifier: Development Status :: 5 - Production/Stable
12
12
  Classifier: Environment :: Web Environment
13
13
  Classifier: Intended Audience :: Developers
@@ -16,7 +16,6 @@ Classifier: Intended Audience :: System Administrators
16
16
  Classifier: License :: OSI Approved :: MIT License
17
17
  Classifier: Operating System :: OS Independent
18
18
  Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.8
20
19
  Classifier: Programming Language :: Python :: 3.9
21
20
  Classifier: Programming Language :: Python :: 3.10
22
21
  Classifier: Programming Language :: Python :: 3.11
@@ -63,7 +62,7 @@ http://anydi.readthedocs.io/
63
62
 
64
63
  ---
65
64
 
66
- `AnyDI` is a modern, lightweight Dependency Injection library suitable for any synchronous or asynchronous applications with Python 3.8+, based on type annotations ([PEP 484](https://peps.python.org/pep-0484/)).
65
+ `AnyDI` is a modern, lightweight Dependency Injection library suitable for any synchronous or asynchronous applications with Python 3.9+, based on type annotations ([PEP 484](https://peps.python.org/pep-0484/)).
67
66
 
68
67
  The key features are:
69
68
 
@@ -0,0 +1,33 @@
1
+ anydi/__init__.py,sha256=EsR-HiMe8cWS9PQbY23ibc91STK1WTn02DFMPV-TNU4,509
2
+ anydi/_container.py,sha256=gBcdz7wplCm-H8sj_QZpQsgISsg-B9RL6LuZ2kR_PdU,16925
3
+ anydi/_context.py,sha256=AczurUT04Rj2Tq5u7xyWRQKD5dMcnL7aMIS7Ym_aCfA,11343
4
+ anydi/_injector.py,sha256=GdI4NdcB72sJPyBFh9ZKyPflEs-6HaUbiHN2H5QIgHY,3454
5
+ anydi/_logger.py,sha256=UpubJUnW83kffFxkhUlObm2DmZX1Pjqoz9YFKS-JOPg,52
6
+ anydi/_module.py,sha256=cgojC7Z7oMtsUnkfSc65cRYOfZ8Q6KwjusNJzx_VSbk,2729
7
+ anydi/_provider.py,sha256=Qho7nXzu3jWSpDRJoTS-4D7C9csWqk5PBtipZqDhMxI,5876
8
+ anydi/_scanner.py,sha256=F2sHgJvkRYXYnu4F5iSrnIPVzwnNeS7tRPXziirh4NI,4898
9
+ anydi/_types.py,sha256=At2VeJgwNC0gwMqdL0tkGtjSFsqOdrQStDwyzAGugr4,796
10
+ anydi/_utils.py,sha256=guw4sFCvsisJmneKWlZi18YDYll_CjlO_f2cH97rDFQ,3280
11
+ anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ anydi/ext/_utils.py,sha256=PHOLjnohC4gbhZESDnnvuup25XTWmQzDaS2y-9SYzaw,2576
13
+ anydi/ext/django/__init__.py,sha256=QI1IABCVgSDTUoh7M9WMECKXwB3xvh04HfQ9TOWw1Mk,223
14
+ anydi/ext/django/_container.py,sha256=cxVoYQG16WP0S_Yv4TnLwuaaT7NVEOhLWO-YdALJUb4,418
15
+ anydi/ext/django/_settings.py,sha256=Z0RlAuXoO73oahWeMkK10w8c-4uCBde-DBpeKTV5USY,853
16
+ anydi/ext/django/_utils.py,sha256=q6X6GApBm0oBK8DnoRZhTq2m4tAdKRYL__gVgKn3idg,3977
17
+ anydi/ext/django/apps.py,sha256=mjbf_mDCpNSriGnILzhRIr8wFHLMEK8sUerbmRku6i0,2844
18
+ anydi/ext/django/middleware.py,sha256=tryIaBVmfPmilGrnKpLNlLCOPN5rw4_pXY3ojFXv3O0,856
19
+ anydi/ext/django/ninja/__init__.py,sha256=kW3grUgWp_nkWSG_-39ADHMrZLGNcj9TsJ9OW8iWWrk,546
20
+ anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI8W-oO2w,2696
21
+ anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
22
+ anydi/ext/fastapi.py,sha256=ebw6-352rMk_YpwPQrL8cUEK0XxGuxDAYCLfHwuDGTQ,2436
23
+ anydi/ext/faststream.py,sha256=asH5Cup5Uu_mG95_OkJZYeLbJ1ttkVQHPRdQTTJmjGE,1898
24
+ anydi/ext/pydantic_settings.py,sha256=8IXXLuG_OvKbvKlBkBRQUHcXgbTpgQUxeWyoMcRIUQM,1488
25
+ anydi/ext/pytest_plugin.py,sha256=Df0pFgAOk-44UFsdZGAOSxElJTJLchs4sk2UZuV-KVk,4212
26
+ anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
+ anydi/ext/starlette/middleware.py,sha256=PKip_omFZDgg7h2OY-nnV2OIS1MbbmrrOJBwG7_Peuw,793
28
+ anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
+ anydi-0.32.0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
30
+ anydi-0.32.0.dist-info/METADATA,sha256=9nTdkO9Woz6ZQCtEBhEkHaV8AgDdfg_DJ6Vt_uX93yw,5112
31
+ anydi-0.32.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
32
+ anydi-0.32.0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
33
+ anydi-0.32.0.dist-info/RECORD,,
@@ -1,31 +0,0 @@
1
- anydi/__init__.py,sha256=aeaBp5vq09sG-e9sqqs9qpUtUIDNfOdFPrlAfE5Ku9E,584
2
- anydi/_container.py,sha256=MyKiQNHKAQ3gb1GzcCZqp6VyUGq2irqqYT7XxX9PXQU,29067
3
- anydi/_context.py,sha256=Wm4DT8Ie_TPchWmIBe8Q9f90dQrGd5lY8H5K85rStgY,12706
4
- anydi/_logger.py,sha256=UpubJUnW83kffFxkhUlObm2DmZX1Pjqoz9YFKS-JOPg,52
5
- anydi/_module.py,sha256=PoMdn-6KlDSiq-0Z7TesSnG-_fg6tyGxC1pjNydplTk,3819
6
- anydi/_scanner.py,sha256=cyEk-K2Q8ssZStq8GrxMeEcCuAZMw-RXrjlgWEevKCs,6667
7
- anydi/_types.py,sha256=i8xFxz8pmFj7SGqwOwae_P9VtiRie6DVLwfaLibLwhc,3653
8
- anydi/_utils.py,sha256=Z6Hdf68LW4f8vihFaxg4kbVICzddP5A1nYXa5Id9AfE,4640
9
- anydi/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- anydi/ext/_utils.py,sha256=2kxLPTMM9Ro3s6-knbqYzONlqRB3hMcwZFFRQGHcFUg,2691
11
- anydi/ext/django/__init__.py,sha256=QI1IABCVgSDTUoh7M9WMECKXwB3xvh04HfQ9TOWw1Mk,223
12
- anydi/ext/django/_container.py,sha256=cxVoYQG16WP0S_Yv4TnLwuaaT7NVEOhLWO-YdALJUb4,418
13
- anydi/ext/django/_settings.py,sha256=cKzFBGtPCsexZ2ZcInubBukIebhxzNfa3F0KuwoZYaA,844
14
- anydi/ext/django/_utils.py,sha256=8-VqdWjgzSE145v6WCgcP0cXG5wtez3ZVGOSD30vD5o,3977
15
- anydi/ext/django/apps.py,sha256=-gj_tqb6goeYMNItr6nwWHYXZwDOdiH8anby0YwnUmw,2866
16
- anydi/ext/django/middleware.py,sha256=iVHWtE829khMY-BXbNNt0g2FrIApKprna7dCG9ObEis,823
17
- anydi/ext/django/ninja/__init__.py,sha256=kW3grUgWp_nkWSG_-39ADHMrZLGNcj9TsJ9OW8iWWrk,546
18
- anydi/ext/django/ninja/_operation.py,sha256=wSWa7D73XTVlOibmOciv2l6JHPe1ERZcXrqI8W-oO2w,2696
19
- anydi/ext/django/ninja/_signature.py,sha256=2cSzKxBIxXLqtwNuH6GSlmjVJFftoGmleWfyk_NVEWw,2207
20
- anydi/ext/fastapi.py,sha256=vhfSyovXuCjvSkx6AiLOTNU975i8wDg72C5fqXQiFLw,2896
21
- anydi/ext/faststream.py,sha256=L4rkWYIO4ZZuWH-8M8NT6_J0bT0Dz_EWO3B6Oj1iFBI,2024
22
- anydi/ext/pydantic_settings.py,sha256=PciVSSyRzk1Uu3Ppz-Y58pqcsZyUVIcZIzYOgJMB_4I,1490
23
- anydi/ext/pytest_plugin.py,sha256=3OWphc4nEzla46_8KR7LXtwGns5eol_YlUWfTf4Cr2Q,3952
24
- anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- anydi/ext/starlette/middleware.py,sha256=Ni0BQaPjs_Ha6zcLZYYJ3-XkslTCnL9aCSa06rnRDMI,1139
26
- anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
27
- anydi-0.30.0.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
28
- anydi-0.30.0.dist-info/METADATA,sha256=DFCfcxI3AhedhOr8XEEb5JfGRv5daeZnxQlN1C_RPUA,5162
29
- anydi-0.30.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
30
- anydi-0.30.0.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
31
- anydi-0.30.0.dist-info/RECORD,,
File without changes