From 2abb7513dc52e9d9f2c73dde91f3b89d8f9492e4 Mon Sep 17 00:00:00 2001 From: pgjones Date: Sun, 14 May 2023 16:09:25 +0100 Subject: [PATCH] Allow for PathLike types for config file variables This follows the Flask practice elsewhere and makes it clear PathLike filenames are valid. --- src/flask/config.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/flask/config.py b/src/flask/config.py index a73dd786..5f921b4d 100644 --- a/src/flask/config.py +++ b/src/flask/config.py @@ -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,