mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-10-11 06:17:02 +03:00
Add stubs for the configuration options
This commit is contained in:
parent
294eec1f27
commit
1c967b74d2
|
@ -117,6 +117,39 @@ class CoroutineDelegate(Delegate):
|
||||||
def __init__(self, coroutine: Coroutine) -> None: ...
|
def __init__(self, coroutine: Coroutine) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigurationOption(Provider):
|
||||||
|
UNDEFINED: object
|
||||||
|
def __init__(self, name: str, root: Configuration) -> None: ...
|
||||||
|
def __call__(self, *args: Injection, **kwargs: Injection) -> Any: ...
|
||||||
|
def __getattr__(self, item: str) -> ConfigurationOption: ...
|
||||||
|
def __getitem__(self, item: str) -> ConfigurationOption: ...
|
||||||
|
def get_name(self) -> str: ...
|
||||||
|
def as_int(self) -> Callable[int]: ...
|
||||||
|
def as_float(self) -> Callable[float]: ...
|
||||||
|
def as_(self, callback: _Callable[..., T], *args: Injection, **kwargs: Injection) -> Callable[T]: ...
|
||||||
|
def update(self, value: Any) -> None: ...
|
||||||
|
def from_ini(self, filepath: str) -> None: ...
|
||||||
|
def from_yaml(self, filepath: str) -> None: ...
|
||||||
|
def from_dict(self, options: Dict[str, Any]) -> None: ...
|
||||||
|
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
class Configuration(Object):
|
||||||
|
DEFAULT_NAME: str = 'config'
|
||||||
|
def __init__(self, name: str = DEFAULT_NAME, default: Optional[Any] = None) -> None: ...
|
||||||
|
def __getattr__(self, item: str) -> ConfigurationOption: ...
|
||||||
|
def __getitem__(self, item: str) -> ConfigurationOption: ...
|
||||||
|
def get_name(self) -> str: ...
|
||||||
|
def get(self, selector: str) -> Any: ...
|
||||||
|
def set(self, selector: str, value: Any) -> OverridingContext: ...
|
||||||
|
def reset_cache(self) -> None: ...
|
||||||
|
def update(self, value: Any) -> None: ...
|
||||||
|
def from_ini(self, filepath: str) -> None: ...
|
||||||
|
def from_yaml(self, filepath: str) -> None: ...
|
||||||
|
def from_dict(self, options: Dict[str, Any]) -> None: ...
|
||||||
|
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
class Factory(Provider, Generic[T]):
|
class Factory(Provider, Generic[T]):
|
||||||
provided_type: Optional[Type]
|
provided_type: Optional[Type]
|
||||||
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
|
def __init__(self, provides: _Callable[..., T], *args: Injection, **kwargs: Injection) -> None: ...
|
||||||
|
|
19
tests/typing/configuration.py
Normal file
19
tests/typing/configuration.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
from dependency_injector import providers
|
||||||
|
|
||||||
|
|
||||||
|
# Test 1: to check the getattr
|
||||||
|
config1 = providers.Configuration()
|
||||||
|
provider1 = providers.Factory(dict, a=config1.a)
|
||||||
|
|
||||||
|
# Test 2: to check the from_*() method
|
||||||
|
config2 = providers.Configuration()
|
||||||
|
config2.from_dict({})
|
||||||
|
config2.from_ini('config.ini')
|
||||||
|
config2.from_yaml('config.yml')
|
||||||
|
config2.from_env('ENV', 'default')
|
||||||
|
|
||||||
|
# Test 3: to check as_*() methods
|
||||||
|
config3 = providers.Configuration()
|
||||||
|
int3: providers.Callable[int] = config3.option.as_int()
|
||||||
|
float3: providers.Callable[float] = config3.option.as_float()
|
||||||
|
int3_custom: providers.Callable[int] = config3.option.as_(int)
|
Loading…
Reference in New Issue
Block a user