From 838667e598dabef34d608c7280a0c5dbf28f35c0 Mon Sep 17 00:00:00 2001 From: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com> Date: Sat, 16 Oct 2021 14:21:37 -0500 Subject: [PATCH] bug: fix Dependency type usage --- di/_task.py | 9 ++++----- di/container.py | 6 ++++-- di/types/providers.py | 10 ++++------ di/types/solved.py | 4 +++- pyproject.toml | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/di/_task.py b/di/_task.py index e01eb2e9..3f2f2671 100644 --- a/di/_task.py +++ b/di/_task.py @@ -12,7 +12,6 @@ AsyncGeneratorProvider, CallableProvider, CoroutineProvider, - Dependency, DependencyType, GeneratorProvider, ) @@ -22,16 +21,16 @@ class Task(Generic[DependencyType]): def __init__( self, dependant: DependantProtocol[DependencyType], - dependencies: List[DependencyParameter[Task[Dependency]]], + dependencies: List[DependencyParameter[Task[Any]]], ) -> None: self.dependant = dependant self.dependencies = dependencies def _gather_params( self, results: Dict[Task[Any], Any] - ) -> Tuple[List[Dependency], Dict[str, Dependency]]: - positional: List[Dependency] = [] - keyword: Dict[str, Dependency] = {} + ) -> Tuple[List[Any], Dict[str, Any]]: + positional: List[Any] = [] + keyword: Dict[str, Any] = {} for dep in self.dependencies: if dep.parameter is not None: if dep.parameter.kind is dep.parameter.kind.POSITIONAL_ONLY: diff --git a/di/container.py b/di/container.py index b2aee9da..b3331294 100644 --- a/di/container.py +++ b/di/container.py @@ -32,10 +32,12 @@ from di.types import FusedContextManager from di.types.dependencies import DependantProtocol, DependencyParameter from di.types.executor import AsyncExecutor, SyncExecutor, Values -from di.types.providers import Dependency, DependencyProviderType, DependencyType +from di.types.providers import DependencyProviderType, DependencyType from di.types.scopes import Scope from di.types.solved import SolvedDependency +Dependency = Any + class Container: _context: ContextVar[ContainerState] @@ -96,7 +98,7 @@ def bind( The bind will be automatically cleared when that scope is exited. If no scope is provided, the current scope is used. """ - return self._state.bind(provider=provider, dependency=dependency) + return self._state.bind(provider=provider, dependency=dependency) # type: ignore def __contains__(self, o: object) -> bool: return o in self._state.binds diff --git a/di/types/providers.py b/di/types/providers.py index bc7a6e35..a17ab758 100644 --- a/di/types/providers.py +++ b/di/types/providers.py @@ -15,11 +15,9 @@ ] -Dependency = Any - DependencyProvider = Union[ - AsyncGeneratorProvider[Dependency], - CoroutineProvider[Dependency], - GeneratorProvider[Dependency], - CallableProvider[Dependency], + AsyncGeneratorProvider[Any], + CoroutineProvider[Any], + GeneratorProvider[Any], + CallableProvider[Any], ] diff --git a/di/types/solved.py b/di/types/solved.py index 37992aab..cecd9dc6 100644 --- a/di/types/solved.py +++ b/di/types/solved.py @@ -5,7 +5,9 @@ from di._task import AsyncTask, SyncTask from di.types.dependencies import DependantProtocol, DependencyParameter -from di.types.providers import Dependency, DependencyType +from di.types.providers import DependencyType + +Dependency = Any @dataclasses.dataclass diff --git a/pyproject.toml b/pyproject.toml index 55d9e8e7..01fd6d3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "di" -version = "0.18.4" +version = "0.18.5" description = "Autowiring dependency injection" authors = ["Adrian Garcia Badaracco "] readme = "README.md"