Add stubs for the configuration options

This commit is contained in:
Roman Mogylatov 2020-08-25 19:56:31 -04:00
parent 294eec1f27
commit 1c967b74d2
2 changed files with 52 additions and 0 deletions

View File

@ -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: ...

View 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)