anydi 0.67.1__tar.gz → 0.67.2__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 (26) hide show
  1. {anydi-0.67.1 → anydi-0.67.2}/PKG-INFO +1 -1
  2. {anydi-0.67.1 → anydi-0.67.2}/anydi/_container.py +14 -19
  3. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/typer.py +3 -3
  4. {anydi-0.67.1 → anydi-0.67.2}/pyproject.toml +1 -1
  5. {anydi-0.67.1 → anydi-0.67.2}/README.md +0 -0
  6. {anydi-0.67.1 → anydi-0.67.2}/anydi/__init__.py +0 -0
  7. {anydi-0.67.1 → anydi-0.67.2}/anydi/_async_lock.py +0 -0
  8. {anydi-0.67.1 → anydi-0.67.2}/anydi/_context.py +0 -0
  9. {anydi-0.67.1 → anydi-0.67.2}/anydi/_decorators.py +0 -0
  10. {anydi-0.67.1 → anydi-0.67.2}/anydi/_injector.py +0 -0
  11. {anydi-0.67.1 → anydi-0.67.2}/anydi/_marker.py +0 -0
  12. {anydi-0.67.1 → anydi-0.67.2}/anydi/_module.py +0 -0
  13. {anydi-0.67.1 → anydi-0.67.2}/anydi/_provider.py +0 -0
  14. {anydi-0.67.1 → anydi-0.67.2}/anydi/_resolver.py +0 -0
  15. {anydi-0.67.1 → anydi-0.67.2}/anydi/_scanner.py +0 -0
  16. {anydi-0.67.1 → anydi-0.67.2}/anydi/_types.py +0 -0
  17. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/__init__.py +0 -0
  18. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/django/__init__.py +0 -0
  19. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/fastapi.py +0 -0
  20. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/faststream.py +0 -0
  21. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/pydantic_settings.py +0 -0
  22. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/pytest_plugin.py +0 -0
  23. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/starlette/__init__.py +0 -0
  24. {anydi-0.67.1 → anydi-0.67.2}/anydi/ext/starlette/middleware.py +0 -0
  25. {anydi-0.67.1 → anydi-0.67.2}/anydi/py.typed +0 -0
  26. {anydi-0.67.1 → anydi-0.67.2}/anydi/testing.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: anydi
3
- Version: 0.67.1
3
+ Version: 0.67.2
4
4
  Summary: Dependency Injection library
5
5
  Keywords: dependency injection,dependencies,di,async,asyncio,application
6
6
  Author: Anton Ruhlov
@@ -23,14 +23,7 @@ from ._module import ModuleDef, ModuleRegistrar
23
23
  from ._provider import Provider, ProviderDef, ProviderKind, ProviderParameter
24
24
  from ._resolver import Resolver
25
25
  from ._scanner import PackageOrIterable, Scanner
26
- from ._types import (
27
- NOT_SET,
28
- Event,
29
- Scope,
30
- is_event_type,
31
- is_iterator_type,
32
- is_none_type,
33
- )
26
+ from ._types import NOT_SET, Event, Scope, is_event_type, is_iterator_type, is_none_type
34
27
 
35
28
  T = TypeVar("T", bound=Any)
36
29
  P = ParamSpec("P")
@@ -437,7 +430,9 @@ class Container:
437
430
  scope_hierarchy = self._scopes.get(scope, ()) if scope != "transient" else ()
438
431
 
439
432
  for parameter in signature.parameters.values():
440
- if parameter.annotation is inspect.Parameter.empty:
433
+ annotation = parameter.annotation
434
+
435
+ if annotation is inspect.Parameter.empty:
441
436
  raise TypeError(
442
437
  f"Missing provider `{name}` "
443
438
  f"dependency `{parameter.name}` annotation."
@@ -452,17 +447,17 @@ class Container:
452
447
  default = parameter.default if has_default else NOT_SET
453
448
 
454
449
  try:
455
- sub_provider = self._get_or_register_provider(parameter.annotation)
450
+ sub_provider = self._get_or_register_provider(annotation)
456
451
  except LookupError as exc:
457
452
  if (defaults and parameter.name in defaults) or has_default:
458
453
  continue
459
454
  # For scoped dependencies, allow unresolved parameters via context.set()
460
455
  if is_scoped:
461
- self._resolver.add_unresolved(parameter.annotation)
456
+ self._resolver.add_unresolved(annotation)
462
457
  parameters.append(
463
458
  ProviderParameter(
464
459
  name=parameter.name,
465
- annotation=parameter.annotation,
460
+ annotation=annotation,
466
461
  default=default,
467
462
  has_default=has_default,
468
463
  provider=None,
@@ -484,11 +479,11 @@ class Container:
484
479
  and sub_provider.scope == scope
485
480
  and any(p.provider is None for p in sub_provider.parameters)
486
481
  ):
487
- self._resolver.add_unresolved(parameter.annotation)
482
+ self._resolver.add_unresolved(annotation)
488
483
  parameters.append(
489
484
  ProviderParameter(
490
485
  name=parameter.name,
491
- annotation=parameter.annotation,
486
+ annotation=annotation,
492
487
  default=default,
493
488
  has_default=has_default,
494
489
  provider=None,
@@ -509,7 +504,7 @@ class Container:
509
504
  parameters.append(
510
505
  ProviderParameter(
511
506
  name=parameter.name,
512
- annotation=parameter.annotation,
507
+ annotation=annotation,
513
508
  default=default,
514
509
  has_default=has_default,
515
510
  provider=sub_provider,
@@ -574,20 +569,20 @@ class Container:
574
569
  """Get provider by interface."""
575
570
  try:
576
571
  return self._providers[interface]
577
- except KeyError as exc:
572
+ except KeyError:
578
573
  raise LookupError(
579
574
  f"The provider interface for `{type_repr(interface)}` has "
580
575
  "not been registered. Please ensure that the provider interface is "
581
576
  "properly registered before attempting to use it."
582
- ) from exc
577
+ ) from None
583
578
 
584
579
  def _get_or_register_provider(
585
580
  self, interface: Any, defaults: dict[str, Any] | None = None
586
581
  ) -> Provider:
587
582
  """Get or register a provider by interface."""
588
583
  try:
589
- return self._providers[interface]
590
- except KeyError:
584
+ return self._get_provider(interface)
585
+ except LookupError:
591
586
  if inspect.isclass(interface) and is_provided(interface):
592
587
  return self._register_provider(
593
588
  interface,
@@ -42,7 +42,7 @@ def _wrap_async_callback_with_injection(
42
42
  callback: Callable[..., Awaitable[Any]],
43
43
  container: Container,
44
44
  sig: inspect.Signature,
45
- non_injected_params: set[inspect.Parameter],
45
+ non_injected_params: list[inspect.Parameter],
46
46
  scopes: set[Scope],
47
47
  ) -> Any:
48
48
  """Wrap async callback with injection in anyio.run()."""
@@ -86,7 +86,7 @@ def _process_callback(callback: Callable[..., Any], container: Container) -> Any
86
86
  """Validate and wrap a callback for dependency injection."""
87
87
  sig = inspect.signature(callback, eval_str=True)
88
88
  injected_param_names: set[str] = set()
89
- non_injected_params: set[inspect.Parameter] = set()
89
+ non_injected_params: list[inspect.Parameter] = []
90
90
  scopes: set[Scope] = set()
91
91
 
92
92
  # Validate parameters and collect which ones need injection
@@ -103,7 +103,7 @@ def _process_callback(callback: Callable[..., Any], container: Container) -> Any
103
103
  if inspect.isclass(interface) and is_provided(interface):
104
104
  scopes.add(interface.__provided__["scope"])
105
105
  else:
106
- non_injected_params.add(processed_parameter)
106
+ non_injected_params.append(processed_parameter)
107
107
 
108
108
  # If no parameters need injection and callback is not async, return original
109
109
  if not injected_param_names and not inspect.iscoroutinefunction(callback):
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "anydi"
3
- version = "0.67.1"
3
+ version = "0.67.2"
4
4
  description = "Dependency Injection library"
5
5
  authors = [{ name = "Anton Ruhlov", email = "antonruhlov@gmail.com" }]
6
6
  requires-python = ">=3.10.0, <3.15"
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