anydi 0.35.0__tar.gz → 0.36.0a0__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.
Files changed (28) hide show
  1. {anydi-0.35.0 → anydi-0.36.0a0}/PKG-INFO +1 -1
  2. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/_container.py +6 -4
  3. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/pytest_plugin.py +33 -15
  4. {anydi-0.35.0 → anydi-0.36.0a0}/pyproject.toml +1 -1
  5. {anydi-0.35.0 → anydi-0.36.0a0}/LICENSE +0 -0
  6. {anydi-0.35.0 → anydi-0.36.0a0}/README.md +0 -0
  7. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/__init__.py +0 -0
  8. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/_context.py +0 -0
  9. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/_provider.py +0 -0
  10. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/_types.py +0 -0
  11. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/_utils.py +0 -0
  12. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/__init__.py +0 -0
  13. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/_utils.py +0 -0
  14. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/__init__.py +0 -0
  15. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/_container.py +0 -0
  16. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/_settings.py +0 -0
  17. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/_utils.py +0 -0
  18. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/apps.py +0 -0
  19. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/middleware.py +0 -0
  20. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/ninja/__init__.py +0 -0
  21. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/ninja/_operation.py +0 -0
  22. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/django/ninja/_signature.py +0 -0
  23. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/fastapi.py +0 -0
  24. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/faststream.py +0 -0
  25. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/pydantic_settings.py +0 -0
  26. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/starlette/__init__.py +0 -0
  27. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/ext/starlette/middleware.py +0 -0
  28. {anydi-0.35.0 → anydi-0.36.0a0}/anydi/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.35.0
3
+ Version: 0.36.0a0
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -536,8 +536,9 @@ class Container:
536
536
  instance = context.get(provider.interface)
537
537
  if instance is None:
538
538
  instance = self._create_instance(provider, context)
539
- context.set(provider.interface, instance)
540
- return instance, True
539
+ if not self._override_instances:
540
+ context.set(provider.interface, instance)
541
+ return instance, True
541
542
  return instance, False
542
543
 
543
544
  async def _aget_or_create_instance(
@@ -547,8 +548,9 @@ class Container:
547
548
  instance = context.get(provider.interface)
548
549
  if instance is None:
549
550
  instance = await self._acreate_instance(provider, context)
550
- context.set(provider.interface, instance)
551
- return instance, True
551
+ if not self._override_instances:
552
+ context.set(provider.interface, instance)
553
+ return instance, True
552
554
  return instance, False
553
555
 
554
556
  def _create_instance(
@@ -6,6 +6,8 @@ from collections.abc import Iterator
6
6
  from typing import Any, Callable, cast
7
7
 
8
8
  import pytest
9
+ from _pytest.python import async_warn_and_skip
10
+ from anyio.pytest_plugin import extract_backend_and_options, get_runner
9
11
 
10
12
  from anydi import Container
11
13
  from anydi._utils import get_typed_parameters
@@ -113,28 +115,44 @@ def _anydi_inject(
113
115
 
114
116
 
115
117
  @pytest.fixture(autouse=True)
116
- async def _anydi_ainject(
118
+ def _anydi_ainject(
117
119
  request: pytest.FixtureRequest,
118
120
  _anydi_should_inject: bool,
119
121
  _anydi_injected_parameter_iterator: Callable[[], Iterator[tuple[str, Any]]],
120
122
  _anydi_unresolved: list[str],
121
123
  ) -> None:
122
124
  """Inject dependencies into the test function."""
123
- if not inspect.iscoroutinefunction(request.function) or not _anydi_should_inject:
125
+ if (
126
+ not inspect.iscoroutinefunction(request.function)
127
+ and not inspect.isasyncgenfunction(request.function)
128
+ or not _anydi_should_inject
129
+ ):
124
130
  return
125
131
 
126
- # Setup the container
127
- container = cast(Container, request.getfixturevalue("anydi_setup_container"))
132
+ # Skip if the anyio backend is not available
133
+ if "anyio_backend" not in request.fixturenames:
134
+ async_warn_and_skip(request.node.nodeid)
128
135
 
129
- for argname, interface in _anydi_injected_parameter_iterator():
130
- # Skip if the interface is not registered
131
- if container.strict and not container.is_registered(interface):
132
- continue
136
+ async def _awrapper() -> None:
137
+ # Setup the container
138
+ container = cast(Container, request.getfixturevalue("anydi_setup_container"))
133
139
 
134
- try:
135
- request.node.funcargs[argname] = await container.aresolve(interface)
136
- except Exception as exc:
137
- logger.warning(
138
- f"Failed to resolve dependency for argument '{argname}'.", exc_info=exc
139
- )
140
- _anydi_unresolved.append(interface)
140
+ for argname, interface in _anydi_injected_parameter_iterator():
141
+ # Skip if the interface is not registered
142
+ if container.strict and not container.is_registered(interface):
143
+ continue
144
+
145
+ try:
146
+ request.node.funcargs[argname] = await container.aresolve(interface)
147
+ except Exception as exc:
148
+ logger.warning(
149
+ f"Failed to resolve dependency for argument '{argname}'.",
150
+ exc_info=exc,
151
+ )
152
+ _anydi_unresolved.append(interface)
153
+
154
+ anyio_backend = request.getfixturevalue("anyio_backend")
155
+ backend_name, backend_options = extract_backend_and_options(anyio_backend)
156
+
157
+ with get_runner(backend_name, backend_options) as runner:
158
+ runner.run_fixture(_awrapper, {})
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "anydi"
3
- version = "0.35.0"
3
+ version = "0.36.0a0"
4
4
  description = "Dependency Injection library"
5
5
  authors = ["Anton Ruhlov <antonruhlov@gmail.com>"]
6
6
  license = "MIT"
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