anydi 0.36.1a2__tar.gz → 0.36.1a3__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.36.1a2 → anydi-0.36.1a3}/PKG-INFO +1 -1
  2. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/_container.py +30 -20
  3. {anydi-0.36.1a2 → anydi-0.36.1a3}/pyproject.toml +1 -1
  4. {anydi-0.36.1a2 → anydi-0.36.1a3}/LICENSE +0 -0
  5. {anydi-0.36.1a2 → anydi-0.36.1a3}/README.md +0 -0
  6. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/__init__.py +0 -0
  7. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/_context.py +0 -0
  8. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/_provider.py +0 -0
  9. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/_types.py +0 -0
  10. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/_utils.py +0 -0
  11. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/__init__.py +0 -0
  12. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/_utils.py +0 -0
  13. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/__init__.py +0 -0
  14. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/_container.py +0 -0
  15. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/_settings.py +0 -0
  16. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/_utils.py +0 -0
  17. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/apps.py +0 -0
  18. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/middleware.py +0 -0
  19. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/ninja/__init__.py +0 -0
  20. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/ninja/_operation.py +0 -0
  21. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/django/ninja/_signature.py +0 -0
  22. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/fastapi.py +0 -0
  23. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/faststream.py +0 -0
  24. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/pydantic_settings.py +0 -0
  25. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/pytest_plugin.py +0 -0
  26. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/starlette/__init__.py +0 -0
  27. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/ext/starlette/middleware.py +0 -0
  28. {anydi-0.36.1a2 → anydi-0.36.1a3}/anydi/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.36.1a2
3
+ Version: 0.36.1a3
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -622,9 +622,7 @@ class Container:
622
622
  return defaults[parameter.name]
623
623
 
624
624
  # Get instance from overrides or context cache
625
- if parameter.annotation in self._override_instances:
626
- return self._override_instances[parameter.annotation]
627
- elif context and parameter.annotation in context:
625
+ if context and parameter.annotation in context:
628
626
  return context[parameter.annotation]
629
627
 
630
628
  # Resolve the instance
@@ -666,9 +664,7 @@ class Container:
666
664
  return defaults[parameter.name]
667
665
 
668
666
  # Get instance from overrides or context cache
669
- if parameter.annotation in self._override_instances:
670
- return self._override_instances[parameter.annotation]
671
- elif context and parameter.annotation in context:
667
+ if context and parameter.annotation in context:
672
668
  return context[parameter.annotation]
673
669
 
674
670
  # Resolve the instance
@@ -713,10 +709,9 @@ class Container:
713
709
  if interface in self._override_instances:
714
710
  return self._override_instances[interface]
715
711
 
716
- if not hasattr(instance, "__dict__"):
717
- return instance
718
-
719
- if hasattr(instance, "__patched__"):
712
+ if not hasattr(instance, "__dict__") or hasattr(
713
+ instance, "__resolver_getter__"
714
+ ):
720
715
  return instance
721
716
 
722
717
  wrapped = {
@@ -725,20 +720,35 @@ class Container:
725
720
  if isinstance(value, InstanceProxy)
726
721
  }
727
722
 
728
- # Custom resolver function
729
- def _resolver(_self: Any, _name: str) -> Any:
730
- if _name in wrapped:
731
- _interface = wrapped[_name]
723
+ def __resolver_getter__(name: str) -> Any:
724
+ if name in wrapped:
725
+ _interface = wrapped[name]
732
726
  # Resolve the dependency if it's wrapped
733
727
  return self.resolve(_interface)
734
- # Fall back to default behavior
735
- return object.__getattribute__(_self, _name)
728
+ raise LookupError
729
+
730
+ if not hasattr(instance.__class__, "__getattribute_patched__"):
731
+
732
+ def __getattribute__(_self: Any, name: str) -> Any:
733
+ # Skip the resolver getter
734
+ if name in {"__resolver_getter__"}:
735
+ return object.__getattribute__(_self, name)
736
+
737
+ if hasattr(_self, "__resolver_getter__"):
738
+ try:
739
+ return _self.__resolver_getter__(name)
740
+ except LookupError:
741
+ pass
742
+
743
+ # Fall back to default behavior
744
+ return object.__getattribute__(_self, name)
736
745
 
737
- # Apply the patched resolver if wrapped attributes exist
738
- if wrapped:
739
- instance.__class__.__getattribute__ = _resolver
746
+ # Apply the patched resolver if wrapped attributes exist
747
+ instance.__class__.__getattribute__ = __getattribute__
748
+ instance.__class__.__getattribute_patched__ = True
740
749
 
741
- instance.__patched__ = True
750
+ # Attach the resolver getter to the instance
751
+ instance.__resolver_getter__ = __resolver_getter__
742
752
 
743
753
  return instance
744
754
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "anydi"
3
- version = "0.36.1a2"
3
+ version = "0.36.1a3"
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