From: Serhiy Storchaka Date: Tue, 19 May 2015 08:00:07 +0000 (+0300) Subject: Issue #23780: Improved error message in os.path.join() with single argument. X-Git-Tag: v3.5.0b1~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5bfc03f430ab13ed84c2c30f2c87e9800b5670a4;p=python Issue #23780: Improved error message in os.path.join() with single argument. Idea by R. David Murray. --- diff --git a/Lib/macpath.py b/Lib/macpath.py index dbcf368468..a90d1053bc 100644 --- a/Lib/macpath.py +++ b/Lib/macpath.py @@ -53,6 +53,8 @@ def join(s, *p): try: colon = _get_colon(s) path = s + if not p: + path[:0] + colon #23780: Ensure compatible data type even if p is null. for t in p: if (not path) or isabs(t): path = t diff --git a/Lib/ntpath.py b/Lib/ntpath.py index cfb4606019..9cc5ca738d 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -81,6 +81,8 @@ def join(path, *paths): seps = '\\/' colon = ':' try: + if not paths: + path[:0] + sep #23780: Ensure compatible data type even if p is null. result_drive, result_path = splitdrive(path) for p in paths: p_drive, p_path = splitdrive(p) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index ea51e11833..09b8897968 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -76,6 +76,8 @@ def join(a, *p): sep = _get_sep(a) path = a try: + if not p: + path[:0] + sep #23780: Ensure compatible data type even if p is null. for b in p: if b.startswith(sep): path = b diff --git a/Lib/test/test_genericpath.py b/Lib/test/test_genericpath.py index f2722bcc8a..6ba55df8c4 100644 --- a/Lib/test/test_genericpath.py +++ b/Lib/test/test_genericpath.py @@ -448,6 +448,10 @@ class CommonTest(GenericTest): self.pathmodule.join(42, 'str') with self.assertRaisesRegex(TypeError, errmsg % 'int'): self.pathmodule.join('str', 42) + with self.assertRaisesRegex(TypeError, errmsg % 'int'): + self.pathmodule.join(42) + with self.assertRaisesRegex(TypeError, errmsg % 'list'): + self.pathmodule.join([]) with self.assertRaisesRegex(TypeError, errmsg % 'bytearray'): self.pathmodule.join(bytearray(b'foo'), bytearray(b'bar')) diff --git a/Misc/NEWS b/Misc/NEWS index 9aa3cf7385..3d8e3166a9 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -49,6 +49,8 @@ Core and Builtins Library ------- +- Issue #23780: Improved error message in os.path.join() with single argument. + - Issue #6598: Increased time precision and random number range in email.utils.make_msgid() to strengthen the uniqueness of the message ID.