From 7e0d45a3b1557a70167802da43794b9b1d59d9ff Mon Sep 17 00:00:00 2001 From: Matthew Gamble Date: Sat, 14 May 2022 12:06:59 +1000 Subject: [PATCH 1/3] Support PathLike as type for filename argument in FileStorage class The code already supports this. Under the hood, it calls os.fsdecode() on filename. It's just the types that need updating. --- CHANGES.rst | 5 +++++ docs/datastructures.rst | 3 ++- src/werkzeug/datastructures.pyi | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 41353ad9e..701debc7c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,5 +1,10 @@ .. currentmodule:: werkzeug +- Add ``os.PathLike`` as a supported type for + ``werkzeug.datastructures.FileStorage`` in the typing information + file. It was already supported by the code. + + Version 2.1.2 ------------- diff --git a/docs/datastructures.rst b/docs/datastructures.rst index 10e3715e2..01432f413 100644 --- a/docs/datastructures.rst +++ b/docs/datastructures.rst @@ -122,7 +122,8 @@ Others .. attribute:: filename - The filename of the file on the client. + The filename of the file on the client. Can be a ``str``, or an + instance of ``os.PathLike``. .. attribute:: name diff --git a/src/werkzeug/datastructures.pyi b/src/werkzeug/datastructures.pyi index 6050f3508..7bf729789 100644 --- a/src/werkzeug/datastructures.pyi +++ b/src/werkzeug/datastructures.pyi @@ -896,7 +896,7 @@ class FileStorage: def __init__( self, stream: Optional[IO[bytes]] = None, - filename: Optional[str] = None, + filename: Union[str, PathLike, None] = None, name: Optional[str] = None, content_type: Optional[str] = None, content_length: Optional[int] = None, From c7f10f4a193e149b5852324e1ecd7b2d54ca6e8b Mon Sep 17 00:00:00 2001 From: pgjones Date: Fri, 22 Jul 2022 13:02:46 +0100 Subject: [PATCH 2/3] Correct the CHANGES format for the unreleased 2.1.3 --- CHANGES.rst | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 701debc7c..4b55f301b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,8 +1,13 @@ .. currentmodule:: werkzeug +Version 2.1.3 +------------- + +Unreleased + - Add ``os.PathLike`` as a supported type for ``werkzeug.datastructures.FileStorage`` in the typing information - file. It was already supported by the code. + file. It was already supported by the code. :pr:`2418` Version 2.1.2 From dfdc7c602fed71082ca11662e53b4c09095af7e7 Mon Sep 17 00:00:00 2001 From: pgjones Date: Fri, 22 Jul 2022 13:21:24 +0100 Subject: [PATCH 3/3] Ignore false positive B023 errors This may be related to https://github.com/PyCQA/flake8-bugbear/issues/269. These errors only occur if flake8 is run with Python 3.8, which is odd. --- src/werkzeug/routing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/werkzeug/routing.py b/src/werkzeug/routing.py index 1d3027b6d..2ffdb9c71 100644 --- a/src/werkzeug/routing.py +++ b/src/werkzeug/routing.py @@ -2007,8 +2007,10 @@ def match( if isinstance(rule.redirect_to, str): def _handle_match(match: t.Match[str]) -> str: - value = rv[match.group(1)] # type: ignore - return rule._converters[match.group(1)].to_url(value) + value = rv[match.group(1)] # type: ignore # noqa: B023 + return rule._converters[match.group(1)].to_url( # noqa: B023 + value + ) redirect_url = _simple_rule_re.sub(_handle_match, rule.redirect_to) else: