bpo-45192: Fix a bug that infers the type of an os.PathLike[bytes] object as str (GH-28323) (GH-29112)

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.
(cherry picked from commit 6270d3eeaf)

Co-authored-by: Kyungmin Lee <rekyungmin@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-10-20 14:25:10 -07:00 committed by GitHub
parent 427ab124b3
commit d33fae7105
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -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 "