From 4ff1a428e2552960233356c6763e0aa885463268 Mon Sep 17 00:00:00 2001 From: Tomas Farias Date: Thu, 14 Nov 2019 17:03:29 -0800 Subject: [PATCH 1/4] Add os.PathLike to exception message raised by _check_arg_types --- Lib/genericpath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/genericpath.py b/Lib/genericpath.py index db11f67d54cc2f..bec3de2438ad9e 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -149,7 +149,7 @@ def _check_arg_types(funcname, *args): elif isinstance(s, bytes): hasbytes = True else: - raise TypeError('%s() argument must be str or bytes, not %r' % + raise TypeError('%s() argument must be str, bytes or os.PathLike object, not %r' % (funcname, s.__class__.__name__)) from None if hasstr and hasbytes: raise TypeError("Can't mix strings and bytes in path components") from None From 34a40e769d0f649554014dcae32e85b3e7f7a627 Mon Sep 17 00:00:00 2001 From: Tomas Farias Date: Fri, 15 Nov 2019 01:29:56 -0800 Subject: [PATCH 2/4] Use f-string and grammar change --- Lib/genericpath.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/genericpath.py b/Lib/genericpath.py index bec3de2438ad9e..ea3aa73ff5962c 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -149,7 +149,7 @@ def _check_arg_types(funcname, *args): elif isinstance(s, bytes): hasbytes = True else: - raise TypeError('%s() argument must be str, bytes or os.PathLike object, not %r' % - (funcname, s.__class__.__name__)) from None + raise TypeError(f'{funcname}() argument must be str, bytes, or ' + f'os.PathLike object, not {s.__class__.__name__}') from None if hasstr and hasbytes: raise TypeError("Can't mix strings and bytes in path components") from None From 75efcbad25def2c3d1ac70d94533434d40a156af Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 15 Nov 2019 09:30:29 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2019-11-15-09-30-29.bpo-38807.PsmRog.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2019-11-15-09-30-29.bpo-38807.PsmRog.rst diff --git a/Misc/NEWS.d/next/Library/2019-11-15-09-30-29.bpo-38807.PsmRog.rst b/Misc/NEWS.d/next/Library/2019-11-15-09-30-29.bpo-38807.PsmRog.rst new file mode 100644 index 00000000000000..2bd7e3deb19ed2 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-11-15-09-30-29.bpo-38807.PsmRog.rst @@ -0,0 +1 @@ +Update :exc:`TypeError` messages for :meth:`os.path.join` to include :class:`os.PathLike` objects as acceptable input types. \ No newline at end of file From 40250c7a8000fae3a23dc07d93514e07ef98cf90 Mon Sep 17 00:00:00 2001 From: Tomas Farias Date: Fri, 15 Nov 2019 02:00:54 -0800 Subject: [PATCH 4/4] Use %r formatting --- Lib/genericpath.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/genericpath.py b/Lib/genericpath.py index ea3aa73ff5962c..ce36451a3af01c 100644 --- a/Lib/genericpath.py +++ b/Lib/genericpath.py @@ -150,6 +150,6 @@ def _check_arg_types(funcname, *args): hasbytes = True else: raise TypeError(f'{funcname}() argument must be str, bytes, or ' - f'os.PathLike object, not {s.__class__.__name__}') from None + f'os.PathLike object, not {s.__class__.__name__!r}') from None if hasstr and hasbytes: raise TypeError("Can't mix strings and bytes in path components") from None