diff options
author | Kyungmin Lee <rekyungmin@gmail.com> | 2021-10-20 19:54:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 19:54:41 (GMT) |
commit | 6270d3eeaf17b50abc4f8f4d97790d66179638e4 (patch) | |
tree | 23d348dc9a50d984a40f12ed968080e973bda6f8 /Lib/tempfile.py | |
parent | bc85eb7a4f16e9e2b6fb713be2466ebb132fd7f2 (diff) | |
download | cpython-6270d3eeaf17b50abc4f8f4d97790d66179638e4.zip cpython-6270d3eeaf17b50abc4f8f4d97790d66179638e4.tar.gz cpython-6270d3eeaf17b50abc4f8f4d97790d66179638e4.tar.bz2 |
bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323)
An object implementing the os.PathLike protocol can represent a file
system path as a str or bytes object.
Therefore, _infer_return_type function should infer os.PathLike[str]
object as str type and os.PathLike[bytes] object as bytes type.
Diffstat (limited to 'Lib/tempfile.py')
-rw-r--r-- | Lib/tempfile.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/tempfile.py b/Lib/tempfile.py index 8570c3b..531cbf3 100644 --- a/Lib/tempfile.py +++ b/Lib/tempfile.py @@ -88,6 +88,10 @@ def _infer_return_type(*args): for arg in args: if arg is None: continue + + if isinstance(arg, _os.PathLike): + arg = _os.fspath(arg) + if isinstance(arg, bytes): if return_type is str: raise TypeError("Can't mix bytes and non-bytes in " |