Fix stubs and add tests

This commit is contained in:
Roman Mogylatov 2020-10-16 16:17:42 -04:00
parent 88b3482ced
commit a0b33dc2dd
2 changed files with 26 additions and 3 deletions

View File

@ -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
@ -31,9 +31,12 @@ class DeclarativeContainer(Container):
def __init__(self, **overriding_providers: Union[Provider, Any]) -> None: ...
def override(container: Container) -> _Callable[[Container], Container]: ...
C = TypeVar('C', bound=DeclarativeContainer)
def copy(container: Container) -> _Callable[[Container], Container]: ...
def override(container: Type[C]) -> _Callable[[Type[C]], Type[C]]: ...
def copy(container: Type[C]) -> _Callable[[Type[C]], Type[C]]: ...
def is_container(instance: Any) -> bool: ...

View File

@ -10,3 +10,23 @@ container1 = Container1()
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 Container21(containers.DeclarativeContainer):
provider = providers.Factory(int)
@containers.copy(Container21)
class Container22(containers.DeclarativeContainer):
...