Merge pull request #5126 from pgjones/pathlike

Allow for PathLike types for config file variables
This commit is contained in:
David Lord 2023-05-14 09:43:35 -07:00 committed by GitHub
commit b80baaf359
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,7 +72,9 @@ class Config(dict):
:param defaults: an optional dictionary of default values
"""
def __init__(self, root_path: str, defaults: dict | None = None) -> None:
def __init__(
self, root_path: str | os.PathLike, defaults: dict | None = None
) -> None:
super().__init__(defaults or {})
self.root_path = root_path
@ -164,7 +166,7 @@ class Config(dict):
return True
def from_pyfile(self, filename: str, silent: bool = False) -> bool:
def from_pyfile(self, filename: str | os.PathLike, silent: bool = False) -> bool:
"""Updates the values in the config from a Python file. This function
behaves as if the file was imported as module with the
:meth:`from_object` function.
@ -233,7 +235,7 @@ class Config(dict):
def from_file(
self,
filename: str,
filename: str | os.PathLike,
load: t.Callable[[t.IO[t.Any]], t.Mapping],
silent: bool = False,
text: bool = True,