From 0dbbf4439297d5f54f8ac4144215507e1037df70 Mon Sep 17 00:00:00 2001 From: Andrey Tikhonov <17@itishka.org> Date: Fri, 4 Oct 2024 22:38:38 +0200 Subject: [PATCH] fix passing type --- src/dishka/registry.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/dishka/registry.py b/src/dishka/registry.py index 5e371f0b..16a2e3c1 100644 --- a/src/dishka/registry.py +++ b/src/dishka/registry.py @@ -30,16 +30,6 @@ from .provider import BaseProvider -class UndecoratedType: - """Container for a type which is decorated in other place.""" - def __init__(self, original: type[Any], depth: int) -> None: - self.original = original - self.level = depth - - def __repr__(self) -> str: - return f"UndecoratedType({self.original}, depth={self.level})" - - class Registry: __slots__ = ("scope", "factories", "compiled", "compiled_async") @@ -49,8 +39,13 @@ def __init__(self, scope: BaseScope): self.compiled: dict[DependencyKey, Callable[..., Any]] = {} self.compiled_async: dict[DependencyKey, Callable[..., Any]] = {} - def add_factory(self, factory: Factory) -> None: - provides = factory.provides + def add_factory( + self, + factory: Factory, + provides: DependencyKey| None = None, + ) -> None: + if provides is None: + provides = factory.provides self.factories[provides] = factory def get_compiled( @@ -508,6 +503,4 @@ def _post_process_generic_factories(self): for registry, factory in found: origin = get_origin(factory.provides.type_hint) origin_key = DependencyKey(origin, factory.provides.component) - factory = copy(factory) - factory.provides = origin_key - registry.add_factory(factory) + registry.add_factory(factory, origin_key)