Make Configuration.from_ methods accept Path (#300)

Co-authored-by: rbusche <rbusche@inserve.de>
This commit is contained in:
Rüdiger Busche 2020-10-16 19:57:28 +02:00 committed by GitHub
parent 39f3f3a623
commit 819023e7aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
from pathlib import Path
from typing import ( from typing import (
TypeVar, TypeVar,
Generic, Generic,
@ -136,8 +137,8 @@ class ConfigurationOption(Provider):
def as_float(self) -> TypedConfigurationOption[float]: ... def as_float(self) -> TypedConfigurationOption[float]: ...
def as_(self, callback: _Callable[..., T], *args: Injection, **kwargs: Injection) -> TypedConfigurationOption[T]: ... def as_(self, callback: _Callable[..., T], *args: Injection, **kwargs: Injection) -> TypedConfigurationOption[T]: ...
def update(self, value: Any) -> None: ... def update(self, value: Any) -> None: ...
def from_ini(self, filepath: str) -> None: ... def from_ini(self, filepath: Union[Path, str]) -> None: ...
def from_yaml(self, filepath: str) -> None: ... def from_yaml(self, filepath: Union[Path, str]) -> None: ...
def from_dict(self, options: Dict[str, Any]) -> None: ... def from_dict(self, options: Dict[str, Any]) -> None: ...
def from_env(self, name: str, default: Optional[Any] = None) -> None: ... def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
@ -157,8 +158,8 @@ class Configuration(Object):
def set(self, selector: str, value: Any) -> OverridingContext: ... def set(self, selector: str, value: Any) -> OverridingContext: ...
def reset_cache(self) -> None: ... def reset_cache(self) -> None: ...
def update(self, value: Any) -> None: ... def update(self, value: Any) -> None: ...
def from_ini(self, filepath: str) -> None: ... def from_ini(self, filepath: Union[Path, str]) -> None: ...
def from_yaml(self, filepath: str) -> None: ... def from_yaml(self, filepath: Union[Path, str]) -> None: ...
def from_dict(self, options: Dict[str, Any]) -> None: ... def from_dict(self, options: Dict[str, Any]) -> None: ...
def from_env(self, name: str, default: Optional[Any] = None) -> None: ... def from_env(self, name: str, default: Optional[Any] = None) -> None: ...

View File

@ -1,3 +1,4 @@
from pathlib import Path
from dependency_injector import providers from dependency_injector import providers
@ -9,7 +10,10 @@ provider1 = providers.Factory(dict, a=config1.a)
config2 = providers.Configuration() config2 = providers.Configuration()
config2.from_dict({}) config2.from_dict({})
config2.from_ini('config.ini') config2.from_ini('config.ini')
config2.from_ini(Path('config.ini'))
config2.from_yaml('config.yml') config2.from_yaml('config.yml')
config2.from_yaml(Path('config.yml'))
config2.from_env('ENV', 'default') config2.from_env('ENV', 'default')
# Test 3: to check as_*() methods # Test 3: to check as_*() methods