mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 11:04:01 +03:00
Fix override and copy decorator stubs (#302)
* Fix stubs and add tests * Fix tests * Fix stubs
This commit is contained in:
parent
88b3482ced
commit
56c9023b2d
|
@ -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: ...
|
||||||
|
|
|
@ -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):
|
||||||
|
...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user