anydi 0.36.1a2__tar.gz → 0.36.1a4__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.
- {anydi-0.36.1a2 → anydi-0.36.1a4}/PKG-INFO +1 -1
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/_container.py +54 -39
- {anydi-0.36.1a2 → anydi-0.36.1a4}/pyproject.toml +1 -1
- {anydi-0.36.1a2 → anydi-0.36.1a4}/LICENSE +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/README.md +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/__init__.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/_context.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/_provider.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/_types.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/_utils.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/__init__.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/_utils.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/__init__.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/_container.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/_settings.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/_utils.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/apps.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/middleware.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/ninja/__init__.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/ninja/_operation.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/django/ninja/_signature.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/fastapi.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/faststream.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/pydantic_settings.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/pytest_plugin.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/starlette/__init__.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/ext/starlette/middleware.py +0 -0
- {anydi-0.36.1a2 → anydi-0.36.1a4}/anydi/py.typed +0 -0
|
@@ -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
|
-
|
|
624
|
+
instance = defaults[parameter.name]
|
|
623
625
|
|
|
624
|
-
#
|
|
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
|
-
|
|
628
|
+
instance = context[parameter.annotation]
|
|
629
629
|
|
|
630
|
-
# Resolve
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
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
|
-
|
|
668
|
+
instance = defaults[parameter.name]
|
|
667
669
|
|
|
668
|
-
#
|
|
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
|
-
|
|
672
|
+
instance = context[parameter.annotation]
|
|
673
673
|
|
|
674
|
-
# Resolve
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
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
|
-
|
|
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
|
-
|
|
729
|
-
|
|
730
|
-
|
|
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
|
-
|
|
735
|
-
|
|
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
|
-
|
|
738
|
-
|
|
739
|
-
instance.__class__.__getattribute__ = _resolver
|
|
751
|
+
# Fall back to default behavior
|
|
752
|
+
return object.__getattribute__(_self, name)
|
|
740
753
|
|
|
741
|
-
|
|
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
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|