Skip to content

Commit

Permalink
bug: fix Dependency type usage
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Oct 16, 2021
1 parent 32c8c52 commit 838667e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
9 changes: 4 additions & 5 deletions di/_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
AsyncGeneratorProvider,
CallableProvider,
CoroutineProvider,
Dependency,
DependencyType,
GeneratorProvider,
)
Expand All @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions di/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions di/types/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
]


Dependency = Any

DependencyProvider = Union[
AsyncGeneratorProvider[Dependency],
CoroutineProvider[Dependency],
GeneratorProvider[Dependency],
CallableProvider[Dependency],
AsyncGeneratorProvider[Any],
CoroutineProvider[Any],
GeneratorProvider[Any],
CallableProvider[Any],
]
4 changes: 3 additions & 1 deletion di/types/solved.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "di"
version = "0.18.4"
version = "0.18.5"
description = "Autowiring dependency injection"
authors = ["Adrian Garcia Badaracco <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 838667e

Please sign in to comment.