anydi 0.36.1a2__py3-none-any.whl → 0.36.1a4__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.
anydi/_container.py CHANGED
@@ -618,27 +618,27 @@ class Container:
618
618
  **defaults: Any,
619
619
  ) -> Any:
620
620
  """Retrieve an instance of a dependency from the scoped context."""
621
+
622
+ # Try to get instance from defaults
621
623
  if parameter.name in defaults:
622
- return defaults[parameter.name]
624
+ instance = defaults[parameter.name]
623
625
 
624
- # Get instance from overrides or context cache
625
- if parameter.annotation in self._override_instances:
626
- return self._override_instances[parameter.annotation]
626
+ # Try to get instance from context
627
627
  elif context and parameter.annotation in context:
628
- return context[parameter.annotation]
628
+ instance = context[parameter.annotation]
629
629
 
630
- # Resolve the instance
631
- try:
632
- instance = self._resolve_parameter(provider, parameter)
633
- except LookupError:
634
- if parameter.default is inspect.Parameter.empty:
635
- raise
636
- instance = parameter.default
630
+ # Resolve new instance
631
+ else:
632
+ try:
633
+ instance = self._resolve_parameter(provider, parameter)
634
+ except LookupError:
635
+ if parameter.default is inspect.Parameter.empty:
636
+ raise
637
+ instance = parameter.default
637
638
 
638
639
  # Wrap the instance in a proxy for testing
639
640
  if self.testing:
640
641
  return InstanceProxy(interface=parameter.annotation, instance=instance)
641
-
642
642
  return instance
643
643
 
644
644
  async def _aget_provided_kwargs(
@@ -662,22 +662,23 @@ class Container:
662
662
  **defaults: Any,
663
663
  ) -> Any:
664
664
  """Asynchronously retrieve an instance of a dependency from the context."""
665
+
666
+ # Try to get instance from defaults
665
667
  if parameter.name in defaults:
666
- return defaults[parameter.name]
668
+ instance = defaults[parameter.name]
667
669
 
668
- # Get instance from overrides or context cache
669
- if parameter.annotation in self._override_instances:
670
- return self._override_instances[parameter.annotation]
670
+ # Try to get instance from context
671
671
  elif context and parameter.annotation in context:
672
- return context[parameter.annotation]
672
+ instance = context[parameter.annotation]
673
673
 
674
- # Resolve the instance
675
- try:
676
- instance = await self._aresolve_parameter(provider, parameter)
677
- except LookupError:
678
- if parameter.default is inspect.Parameter.empty:
679
- raise
680
- instance = parameter.default
674
+ # Resolve new instance
675
+ else:
676
+ try:
677
+ instance = await self._aresolve_parameter(provider, parameter)
678
+ except LookupError:
679
+ if parameter.default is inspect.Parameter.empty:
680
+ raise
681
+ instance = parameter.default
681
682
 
682
683
  # Wrap the instance in a proxy for testing
683
684
  if self.testing:
@@ -713,10 +714,9 @@ class Container:
713
714
  if interface in self._override_instances:
714
715
  return self._override_instances[interface]
715
716
 
716
- if not hasattr(instance, "__dict__"):
717
- return instance
718
-
719
- if hasattr(instance, "__patched__"):
717
+ if not hasattr(instance, "__dict__") or hasattr(
718
+ instance, "__resolver_getter__"
719
+ ):
720
720
  return instance
721
721
 
722
722
  wrapped = {
@@ -725,20 +725,35 @@ class Container:
725
725
  if isinstance(value, InstanceProxy)
726
726
  }
727
727
 
728
- # Custom resolver function
729
- def _resolver(_self: Any, _name: str) -> Any:
730
- if _name in wrapped:
731
- _interface = wrapped[_name]
728
+ def __resolver_getter__(name: str) -> Any:
729
+ if name in wrapped:
730
+ _interface = wrapped[name]
732
731
  # Resolve the dependency if it's wrapped
733
732
  return self.resolve(_interface)
734
- # Fall back to default behavior
735
- return object.__getattribute__(_self, _name)
733
+ raise LookupError
734
+
735
+ # Attach the resolver getter to the instance
736
+ instance.__resolver_getter__ = __resolver_getter__
737
+
738
+ if not hasattr(instance.__class__, "__getattribute_patched__"):
739
+
740
+ def __getattribute__(_self: Any, name: str) -> Any:
741
+ # Skip the resolver getter
742
+ if name in {"__resolver_getter__"}:
743
+ return object.__getattribute__(_self, name)
744
+
745
+ if hasattr(_self, "__resolver_getter__"):
746
+ try:
747
+ return _self.__resolver_getter__(name)
748
+ except LookupError:
749
+ pass
736
750
 
737
- # Apply the patched resolver if wrapped attributes exist
738
- if wrapped:
739
- instance.__class__.__getattribute__ = _resolver
751
+ # Fall back to default behavior
752
+ return object.__getattribute__(_self, name)
740
753
 
741
- instance.__patched__ = True
754
+ # Apply the patched resolver if wrapped attributes exist
755
+ instance.__class__.__getattribute__ = __getattribute__
756
+ instance.__class__.__getattribute_patched__ = True
742
757
 
743
758
  return instance
744
759
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.36.1a2
3
+ Version: 0.36.1a4
4
4
  Summary: Dependency Injection library
5
5
  Home-page: https://github.com/antonrh/anydi
6
6
  License: MIT
@@ -1,5 +1,5 @@
1
1
  anydi/__init__.py,sha256=OfRg2EfXD65pHTGQKhfkABMwUhw5LvsuTQV_Tv4V4wk,501
2
- anydi/_container.py,sha256=Nf8fG7aFebE8DWFE41MzsiTkxN7J0_MHX1qfG-4nujo,37715
2
+ anydi/_container.py,sha256=LSa1IMR8JeAtA5im9EWU8NOKqSCDjKmxXRt9mVXPAf4,38251
3
3
  anydi/_context.py,sha256=7LV_SL4QWkJeiG7_4D9PZ5lmU-MPzhofxC95zCgY9Gc,2651
4
4
  anydi/_provider.py,sha256=W42y8wbsnWbb9B9gI-pnEa-lsz68nK0VIm55CJW3pWg,7457
5
5
  anydi/_types.py,sha256=Vttj9GTp9g0KKpK-uqolLfVZJPIM7f7_YL8bPlablcQ,1539
@@ -22,8 +22,8 @@ anydi/ext/pytest_plugin.py,sha256=ShGhiZnP1KyMHhnc9Ci1RKAuHVhw628OTS2P2BLEOfc,50
22
22
  anydi/ext/starlette/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
23
23
  anydi/ext/starlette/middleware.py,sha256=9CQtGg5ZzUz2gFSzJr8U4BWzwNjK8XMctm3n52M77Z0,792
24
24
  anydi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
- anydi-0.36.1a2.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
- anydi-0.36.1a2.dist-info/METADATA,sha256=UH6N4WaWq8NIEDk_RGBFqA9mPAu-zYAl1pFrLA8C8TY,5066
27
- anydi-0.36.1a2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
- anydi-0.36.1a2.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
- anydi-0.36.1a2.dist-info/RECORD,,
25
+ anydi-0.36.1a4.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
+ anydi-0.36.1a4.dist-info/METADATA,sha256=cDcue6lJu_2S7GNsR8ryi_C_lAti0rSKuXZebraSXRA,5066
27
+ anydi-0.36.1a4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
+ anydi-0.36.1a4.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
+ anydi-0.36.1a4.dist-info/RECORD,,