Skip to content

Fix override and copy decorator stubs #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/dependency_injector/containers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from types import ModuleType
from typing import Type, Dict, Tuple, Optional, Any, Union, ClassVar, Callable as _Callable, Iterable
from typing import Type, Dict, Tuple, Optional, Any, Union, ClassVar, Callable as _Callable, Iterable, TypeVar

from .providers import Provider

Expand Down Expand Up @@ -31,9 +31,14 @@ class DeclarativeContainer(Container):
def __init__(self, **overriding_providers: Union[Provider, Any]) -> None: ...


def override(container: Container) -> _Callable[[Container], Container]: ...
C = TypeVar('C', bound=DeclarativeContainer)
C_Overriding = TypeVar('C_Overriding', bound=DeclarativeContainer)


def copy(container: Container) -> _Callable[[Container], Container]: ...
def override(container: Type[C]) -> _Callable[[Type[C_Overriding]], Type[C_Overriding]]: ...


def copy(container: Type[C]) -> _Callable[[Type[C_Overriding]], Type[C_Overriding]]: ...


def is_container(instance: Any) -> bool: ...
20 changes: 20 additions & 0 deletions tests/typing/declarative_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,23 @@ class Container1(containers.DeclarativeContainer):
container1_type: containers.Container = Container1()
provider1: providers.Provider = container1.provider
val1: int = container1.provider(3)


# Test 2: to check @override decorator
class Container21(containers.DeclarativeContainer):
provider = providers.Factory(int)


@containers.override(Container21)
class Container22(containers.DeclarativeContainer):
...


# Test 3: to check @copy decorator
class Container31(containers.DeclarativeContainer):
provider = providers.Factory(int)


@containers.copy(Container31)
class Container32(containers.DeclarativeContainer):
...