Skip to content

Commit 819023e

Browse files
JarnoRFBrbusche
andauthored
Make Configuration.from_ methods accept Path (#300)
Co-authored-by: rbusche <rbusche@inserve.de>
1 parent 39f3f3a commit 819023e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/dependency_injector/providers.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from pathlib import Path
34
from typing import (
45
TypeVar,
56
Generic,
@@ -136,8 +137,8 @@ class ConfigurationOption(Provider):
136137
def as_float(self) -> TypedConfigurationOption[float]: ...
137138
def as_(self, callback: _Callable[..., T], *args: Injection, **kwargs: Injection) -> TypedConfigurationOption[T]: ...
138139
def update(self, value: Any) -> None: ...
139-
def from_ini(self, filepath: str) -> None: ...
140-
def from_yaml(self, filepath: str) -> None: ...
140+
def from_ini(self, filepath: Union[Path, str]) -> None: ...
141+
def from_yaml(self, filepath: Union[Path, str]) -> None: ...
141142
def from_dict(self, options: Dict[str, Any]) -> None: ...
142143
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
143144

@@ -157,8 +158,8 @@ class Configuration(Object):
157158
def set(self, selector: str, value: Any) -> OverridingContext: ...
158159
def reset_cache(self) -> None: ...
159160
def update(self, value: Any) -> None: ...
160-
def from_ini(self, filepath: str) -> None: ...
161-
def from_yaml(self, filepath: str) -> None: ...
161+
def from_ini(self, filepath: Union[Path, str]) -> None: ...
162+
def from_yaml(self, filepath: Union[Path, str]) -> None: ...
162163
def from_dict(self, options: Dict[str, Any]) -> None: ...
163164
def from_env(self, name: str, default: Optional[Any] = None) -> None: ...
164165

tests/typing/configuration.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from dependency_injector import providers
23

34

@@ -9,7 +10,10 @@
910
config2 = providers.Configuration()
1011
config2.from_dict({})
1112
config2.from_ini('config.ini')
13+
config2.from_ini(Path('config.ini'))
14+
1215
config2.from_yaml('config.yml')
16+
config2.from_yaml(Path('config.yml'))
1317
config2.from_env('ENV', 'default')
1418

1519
# Test 3: to check as_*() methods

0 commit comments

Comments
 (0)