Repository: reagento/dishka
Pull request #377 (2025-02-25 09:03:19)

Move provider related thing together


Patch:
diff --git a/src/dishka/__init__.py b/src/dishka/__init__.py
index eabac46..8a814ca 100644
--- a/src/dishka/__init__.py
+++ b/src/dishka/__init__.py
@@ -25,13 +25,6 @@ __all__ = [
 
 from .async_container import AsyncContainer, make_async_container
 from .container import Container, make_container
-from .dependency_source import (
-    alias,
-    decorate,
-    from_context,
-    provide,
-    provide_all,
-)
 from .entities.component import DEFAULT_COMPONENT, Component
 from .entities.depends_marker import FromDishka
 from .entities.key import DependencyKey, FromComponent
@@ -39,4 +32,11 @@ from .entities.provides_marker import AnyOf
 from .entities.scope import BaseScope, Scope, new_scope
 from .entities.validation_settigs import STRICT_VALIDATION, ValidationSettings
 from .entities.with_parents import WithParents
-from .provider import Provider
+from .provider import (
+    Provider,
+    alias,
+    decorate,
+    from_context,
+    provide,
+    provide_all,
+)
diff --git a/src/dishka/dependency_source/__init__.py b/src/dishka/dependency_source/__init__.py
index 18218e7..c6051ff 100644
--- a/src/dishka/dependency_source/__init__.py
+++ b/src/dishka/dependency_source/__init__.py
@@ -1,23 +1,20 @@
 __all__ = [
     "Alias",
+    "CompositeDependencySource",
     "ContextVariable",
     "Decorator",
     "DependencySource",
     "Factory",
-    "alias",
-    "context_var",
-    "decorate",
-    "from_context",
-    "provide",
-    "provide_all",
+    "context_stub",
+    "ensure_composite",
 ]
 
 from .alias import Alias
-from .composite import DependencySource
-from .context_var import ContextVariable
+from .composite import (
+    CompositeDependencySource,
+    DependencySource,
+    ensure_composite,
+)
+from .context_var import ContextVariable, context_stub
 from .decorator import Decorator
 from .factory import Factory
-from .make_alias import alias
-from .make_context_var import from_context
-from .make_decorator import decorate
-from .make_factory import provide, provide_all
diff --git a/src/dishka/provider/__init__.py b/src/dishka/provider/__init__.py
new file mode 100644
index 0000000..2f95d96
--- /dev/null
+++ b/src/dishka/provider/__init__.py
@@ -0,0 +1,17 @@
+__all__ = [
+    "BaseProvider",
+    "Provider",
+    "ProviderWrapper",
+    "alias",
+    "decorate",
+    "from_context",
+    "provide",
+    "provide_all",
+]
+
+from .base_provider import BaseProvider, ProviderWrapper
+from .make_alias import alias
+from .make_context_var import from_context
+from .make_decorator import decorate
+from .make_factory import provide, provide_all
+from .provider import Provider
diff --git a/src/dishka/provider/base_provider.py b/src/dishka/provider/base_provider.py
new file mode 100644
index 0000000..ec2ea4f
--- /dev/null
+++ b/src/dishka/provider/base_provider.py
@@ -0,0 +1,25 @@
+from dishka.dependency_source import (
+    Alias,
+    ContextVariable,
+    Decorator,
+    Factory,
+)
+from dishka.entities.component import Component
+
+
+class BaseProvider:
+    def __init__(self, component: Component | None) -> None:
+        if component is not None:
+            self.component = component
+        self.factories: list[Factory] = []
+        self.aliases: list[Alias] = []
+        self.decorators: list[Decorator] = []
+        self.context_vars: list[ContextVariable] = []
+
+
+class ProviderWrapper(BaseProvider):
+    def __init__(self, component: Component, provider: BaseProvider) -> None:
+        super().__init__(component)
+        self.factories.extend(provider.factories)
+        self.aliases.extend(provider.aliases)
+        self.decorators.extend(provider.decorators)
diff --git a/src/dishka/dependency_source/make_alias.py b/src/dishka/provider/make_alias.py
similarity index 89%
rename from src/dishka/dependency_source/make_alias.py
rename to src/dishka/provider/make_alias.py
index 91821b7..92725bc 100644
--- a/src/dishka/dependency_source/make_alias.py
+++ b/src/dishka/provider/make_alias.py
@@ -1,9 +1,12 @@
 from typing import Any
 
+from dishka.dependency_source import (
+    Alias,
+    CompositeDependencySource,
+    ensure_composite,
+)
 from dishka.entities.component import Component
 from dishka.entities.key import DependencyKey
-from .alias import Alias
-from .composite import CompositeDependencySource, ensure_composite
 from .unpack_provides import unpack_alias
 
 
diff --git a/src/dishka/dependency_source/make_context_var.py b/src/dishka/provider/make_context_var.py
similarity index 86%
rename from src/dishka/dependency_source/make_context_var.py
rename to src/dishka/provider/make_context_var.py
index 13da74d..d9969bd 100644
--- a/src/dishka/dependency_source/make_context_var.py
+++ b/src/dishka/provider/make_context_var.py
@@ -1,10 +1,13 @@
 from typing import Any
 
+from dishka.dependency_source import (
+    CompositeDependencySource,
+    ContextVariable,
+    context_stub,
+)
 from dishka.entities.component import DEFAULT_COMPONENT
 from dishka.entities.key import DependencyKey
 from dishka.entities.scope import BaseScope
-from .composite import CompositeDependencySource
-from .context_var import ContextVariable, context_stub
 
 
 def from_context(
diff --git a/src/dishka/dependency_source/make_decorator.py b/src/dishka/provider/make_decorator.py
similarity index 94%
rename from src/dishka/dependency_source/make_decorator.py
rename to src/dishka/provider/make_decorator.py
index 33736d4..78e5147 100644
--- a/src/dishka/dependency_source/make_decorator.py
+++ b/src/dishka/provider/make_decorator.py
@@ -1,9 +1,12 @@
 from collections.abc import Callable
 from typing import Any, overload
 
+from dishka.dependency_source import (
+    CompositeDependencySource,
+    Decorator,
+    ensure_composite,
+)
 from dishka.text_rendering import get_name
-from .composite import CompositeDependencySource, ensure_composite
-from .decorator import Decorator
 from .make_factory import make_factory
 from .unpack_provides import unpack_decorator
 
diff --git a/src/dishka/dependency_source/make_factory.py b/src/dishka/provider/make_factory.py
similarity index 99%
rename from src/dishka/dependency_source/make_factory.py
rename to src/dishka/provider/make_factory.py
index 79e16ed..903d468 100644
--- a/src/dishka/dependency_source/make_factory.py
+++ b/src/dishka/provider/make_factory.py
@@ -45,6 +45,11 @@ from dishka._adaptix.type_tools.generic_resolver import (
     GenericResolver,
     MembersStorage,
 )
+from dishka.dependency_source import (
+    CompositeDependencySource,
+    Factory,
+    ensure_composite,
+)
 from dishka.entities.factory_type import FactoryType
 from dishka.entities.key import (
     dependency_key_to_hint,
@@ -54,8 +59,6 @@ from dishka.entities.key import (
 from dishka.entities.provides_marker import ProvideMultiple
 from dishka.entities.scope import BaseScope
 from dishka.text_rendering import get_name
-from .composite import CompositeDependencySource, ensure_composite
-from .factory import Factory
 from .unpack_provides import unpack_factory
 
 _empty = signature(lambda a: 0).parameters["a"].annotation
diff --git a/src/dishka/provider.py b/src/dishka/provider/provider.py
similarity index 88%
rename from src/dishka/provider.py
rename to src/dishka/provider/provider.py
index 73f6d6c..75eb49e 100644
--- a/src/dishka/provider.py
+++ b/src/dishka/provider/provider.py
@@ -1,23 +1,22 @@
-from __future__ import annotations
-
 import inspect
 from collections.abc import Callable, Sequence
 from typing import Any, TypeGuard
 
-from dishka.entities.component import DEFAULT_COMPONENT, Component
-from dishka.entities.scope import BaseScope
-from .dependency_source import (
+from dishka.dependency_source import (
     Alias,
+    CompositeDependencySource,
     ContextVariable,
     Decorator,
     DependencySource,
     Factory,
-    alias,
-    from_context,
 )
-from .dependency_source.composite import CompositeDependencySource
-from .dependency_source.make_decorator import decorate_on_instance
-from .dependency_source.make_factory import (
+from dishka.entities.component import DEFAULT_COMPONENT, Component
+from dishka.entities.scope import BaseScope
+from .base_provider import BaseProvider, ProviderWrapper
+from .make_alias import alias
+from .make_context_var import from_context
+from .make_decorator import decorate_on_instance
+from .make_factory import (
     provide_all_on_instance,
     provide_on_instance,
 )
@@ -29,15 +28,6 @@ def is_dependency_source(
     return isinstance(attribute, CompositeDependencySource)
 
 
-class BaseProvider:
-    def __init__(self, component: Component | None) -> None:
-        if component is not None:
-            self.component = component
-        self.factories: list[Factory] = []
-        self.aliases: list[Alias] = []
-        self.decorators: list[Decorator] = []
-        self.context_vars: list[ContextVariable] = []
-
 
 class Provider(BaseProvider):
     """
@@ -224,11 +214,3 @@ class Provider(BaseProvider):
             sources=composite.dependency_sources,
         )
         return composite
-
-
-class ProviderWrapper(BaseProvider):
-    def __init__(self, component: Component, provider: Provider) -> None:
-        super().__init__(component)
-        self.factories.extend(provider.factories)
-        self.aliases.extend(provider.aliases)
-        self.decorators.extend(provider.decorators)
diff --git a/src/dishka/dependency_source/unpack_provides.py b/src/dishka/provider/unpack_provides.py
similarity index 94%
rename from src/dishka/dependency_source/unpack_provides.py
rename to src/dishka/provider/unpack_provides.py
index ed1b62b..2457e03 100644
--- a/src/dishka/dependency_source/unpack_provides.py
+++ b/src/dishka/provider/unpack_provides.py
@@ -1,12 +1,14 @@
 from collections.abc import Sequence
 from typing import get_args, get_origin
 
+from dishka.dependency_source import (
+    Alias,
+    Decorator,
+    DependencySource,
+    Factory,
+)
 from dishka.entities.key import DependencyKey
 from dishka.entities.provides_marker import ProvideMultiple
-from .alias import Alias
-from .composite import DependencySource
-from .decorator import Decorator
-from .factory import Factory
 
 
 def unpack_factory(factory: Factory) -> Sequence[DependencySource]:


Test patch:
diff --git a/tests/unit/container/test_context_vars.py b/tests/unit/container/test_context_vars.py
index 74c66e6..d9603c6 100644
--- a/tests/unit/container/test_context_vars.py
+++ b/tests/unit/container/test_context_vars.py
@@ -6,11 +6,11 @@ from dishka import (
     Provider,
     Scope,
     decorate,
+    from_context,
     make_async_container,
     make_container,
     provide,
 )
-from dishka.dependency_source import from_context
 from dishka.exceptions import InvalidGraphError, NoContextValueError
 
 
diff --git a/tests/unit/container/test_dynamic.py b/tests/unit/container/test_dynamic.py
index 66c226b..ad4cc43 100644
--- a/tests/unit/container/test_dynamic.py
+++ b/tests/unit/container/test_dynamic.py
@@ -1,7 +1,13 @@
 from typing import NewType
 
-from dishka import Container, Provider, Scope, make_container, provide
-from dishka.dependency_source import from_context
+from dishka import (
+    Container,
+    Provider,
+    Scope,
+    from_context,
+    make_container,
+    provide,
+)
 
 Request = NewType("Request", int)
 
diff --git a/tests/unit/test_provider.py b/tests/unit/test_provider.py
index c5b0e67..6cc04e3 100644
--- a/tests/unit/test_provider.py
+++ b/tests/unit/test_provider.py
@@ -4,12 +4,12 @@ from typing import Any, Protocol
 import pytest
 
 from dishka import Provider, Scope, alias, decorate, make_container, provide
-from dishka.dependency_source.make_factory import make_factory, provide_all
 from dishka.entities.factory_type import FactoryType
 from dishka.entities.key import (
     hint_to_dependency_key,
     hints_to_dependency_keys,
 )
+from dishka.provider.make_factory import make_factory, provide_all
 from .sample_providers import (
     ClassA,
     async_func_a,
diff --git a/tests/unit/text_rendering/test_path.py b/tests/unit/text_rendering/test_path.py
index 353544d..9736a1b 100644
--- a/tests/unit/text_rendering/test_path.py
+++ b/tests/unit/text_rendering/test_path.py
@@ -2,7 +2,7 @@ import textwrap
 
 import pytest
 
-from dishka.dependency_source.make_factory import make_factory
+from dishka.provider.make_factory import make_factory
 from dishka.text_rendering.path import PathRenderer