Fix override and copy decorator stubs (#302)

* Fix stubs and add tests

* Fix tests

* Fix stubs
This commit is contained in:
Roman Mogylatov 2020-10-16 16:36:07 -04:00 committed by GitHub
parent 88b3482ced
commit 56c9023b2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -1,5 +1,5 @@
from types import ModuleType 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 from .providers import Provider
@ -31,9 +31,14 @@ class DeclarativeContainer(Container):
def __init__(self, **overriding_providers: Union[Provider, Any]) -> None: ... 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: ... def is_container(instance: Any) -> bool: ...

View File

@ -10,3 +10,23 @@ container1 = Container1()
container1_type: containers.Container = Container1() container1_type: containers.Container = Container1()
provider1: providers.Provider = container1.provider provider1: providers.Provider = container1.provider
val1: int = container1.provider(3) 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):
...