]> granicus.if.org Git - python/commitdiff
Issue #23780: Improved error message in os.path.join() with single argument.
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 19 May 2015 08:00:07 +0000 (11:00 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Tue, 19 May 2015 08:00:07 +0000 (11:00 +0300)
Idea by R. David Murray.

Lib/macpath.py
Lib/ntpath.py
Lib/posixpath.py
Lib/test/test_genericpath.py
Misc/NEWS

index dbcf3684684e60a39ded28320c5c12d193a02178..a90d1053bc83d084e2e35867936fe7cf531e46d8 100644 (file)
@@ -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
index cfb4606019806bc68007cabb4d8a7d850254e532..9cc5ca738d4a54fbb9f90180e8e479d1f27e3f60 100644 (file)
@@ -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)
index ea51e1183384b2f293a96594a30ebef38d7c2c97..09b889796849bd71bf622f92c7b76ba6832c422a 100644 (file)
@@ -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
index f2722bcc8a51fa91a2ee652eecd40c4636f3b80d..6ba55df8c405f9676ced59fcb25c5d1da784974e 100644 (file)
@@ -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'))
 
index 9aa3cf73851bab07bd21c785c27d7752122467c7..3d8e3166a9471d6dc5c37a007257dfb0b9cc0d8e 100644 (file)
--- 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.