anydi 0.36.1a3__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,25 +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 context and parameter.annotation in context:
626
- return context[parameter.annotation]
626
+ # Try to get instance from context
627
+ elif context and parameter.annotation in context:
628
+ instance = context[parameter.annotation]
627
629
 
628
- # Resolve the instance
629
- try:
630
- instance = self._resolve_parameter(provider, parameter)
631
- except LookupError:
632
- if parameter.default is inspect.Parameter.empty:
633
- raise
634
- 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
635
638
 
636
639
  # Wrap the instance in a proxy for testing
637
640
  if self.testing:
638
641
  return InstanceProxy(interface=parameter.annotation, instance=instance)
639
-
640
642
  return instance
641
643
 
642
644
  async def _aget_provided_kwargs(
@@ -660,20 +662,23 @@ class Container:
660
662
  **defaults: Any,
661
663
  ) -> Any:
662
664
  """Asynchronously retrieve an instance of a dependency from the context."""
665
+
666
+ # Try to get instance from defaults
663
667
  if parameter.name in defaults:
664
- return defaults[parameter.name]
668
+ instance = defaults[parameter.name]
665
669
 
666
- # Get instance from overrides or context cache
667
- if context and parameter.annotation in context:
668
- return context[parameter.annotation]
670
+ # Try to get instance from context
671
+ elif context and parameter.annotation in context:
672
+ instance = context[parameter.annotation]
669
673
 
670
- # Resolve the instance
671
- try:
672
- instance = await self._aresolve_parameter(provider, parameter)
673
- except LookupError:
674
- if parameter.default is inspect.Parameter.empty:
675
- raise
676
- 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
677
682
 
678
683
  # Wrap the instance in a proxy for testing
679
684
  if self.testing:
@@ -727,6 +732,9 @@ class Container:
727
732
  return self.resolve(_interface)
728
733
  raise LookupError
729
734
 
735
+ # Attach the resolver getter to the instance
736
+ instance.__resolver_getter__ = __resolver_getter__
737
+
730
738
  if not hasattr(instance.__class__, "__getattribute_patched__"):
731
739
 
732
740
  def __getattribute__(_self: Any, name: str) -> Any:
@@ -747,9 +755,6 @@ class Container:
747
755
  instance.__class__.__getattribute__ = __getattribute__
748
756
  instance.__class__.__getattribute_patched__ = True
749
757
 
750
- # Attach the resolver getter to the instance
751
- instance.__resolver_getter__ = __resolver_getter__
752
-
753
758
  return instance
754
759
 
755
760
  def is_resolved(self, interface: AnyInterface) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: anydi
3
- Version: 0.36.1a3
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=iJy5GoGDvs7CmV7NsTtzfnl1k53wWky6IvT0vCLAD2k,38090
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.1a3.dist-info/LICENSE,sha256=V6rU8a8fv6o2jQ-7ODHs0XfDFimot8Q6Km6CylRIDTo,1069
26
- anydi-0.36.1a3.dist-info/METADATA,sha256=KacqHtuQbewO_xqZOchuioqBcgXuHcLiGjHUsp8hDDM,5066
27
- anydi-0.36.1a3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
28
- anydi-0.36.1a3.dist-info/entry_points.txt,sha256=GmQblwzxFg42zva1HyBYJJ7TvrTIcSAGBHmyi3bvsi4,42
29
- anydi-0.36.1a3.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,,