(original) (raw)

changeset: 96154:84af71e8c051 user: Serhiy Storchaka storchaka@gmail.com date: Tue May 19 11:00:07 2015 +0300 files: Lib/macpath.py Lib/ntpath.py Lib/posixpath.py Lib/test/test_genericpath.py Misc/NEWS description: Issue #23780: Improved error message in os.path.join() with single argument. Idea by R. David Murray. diff -r 933addbc7041 -r 84af71e8c051 Lib/macpath.py --- a/Lib/macpath.py Tue May 19 10:10:15 2015 +0300 +++ b/Lib/macpath.py Tue May 19 11:00:07 2015 +0300 @@ -53,6 +53,8 @@ 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 -r 933addbc7041 -r 84af71e8c051 Lib/ntpath.py --- a/Lib/ntpath.py Tue May 19 10:10:15 2015 +0300 +++ b/Lib/ntpath.py Tue May 19 11:00:07 2015 +0300 @@ -81,6 +81,8 @@ 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 -r 933addbc7041 -r 84af71e8c051 Lib/posixpath.py --- a/Lib/posixpath.py Tue May 19 10:10:15 2015 +0300 +++ b/Lib/posixpath.py Tue May 19 11:00:07 2015 +0300 @@ -76,6 +76,8 @@ 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 -r 933addbc7041 -r 84af71e8c051 Lib/test/test_genericpath.py --- a/Lib/test/test_genericpath.py Tue May 19 10:10:15 2015 +0300 +++ b/Lib/test/test_genericpath.py Tue May 19 11:00:07 2015 +0300 @@ -448,6 +448,10 @@ 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 -r 933addbc7041 -r 84af71e8c051 Misc/NEWS --- a/Misc/NEWS Tue May 19 10:10:15 2015 +0300 +++ b/Misc/NEWS Tue May 19 11:00:07 2015 +0300 @@ -49,6 +49,8 @@ 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. /storchaka@gmail.com