[Python-checkins] r59770 - in python/trunk: Lib/ntpath.py Lib/posixpath.py Lib/test/test_ntpath.py Lib/test/test_posixpath.py Misc/NEWS

georg.brandl python-checkins at python.org
Sun Jan 6 15:27:16 CET 2008


Author: georg.brandl
Date: Sun Jan  6 15:27:15 2008
New Revision: 59770

Modified:
   python/trunk/Lib/ntpath.py
   python/trunk/Lib/posixpath.py
   python/trunk/Lib/test/test_ntpath.py
   python/trunk/Lib/test/test_posixpath.py
   python/trunk/Misc/NEWS
Log:
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.


Modified: python/trunk/Lib/ntpath.py
==============================================================================
--- python/trunk/Lib/ntpath.py	(original)
+++ python/trunk/Lib/ntpath.py	Sun Jan  6 15:27:15 2008
@@ -490,4 +490,6 @@
         i += 1
 
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+    if not rel_list:
+        return curdir
     return join(*rel_list)

Modified: python/trunk/Lib/posixpath.py
==============================================================================
--- python/trunk/Lib/posixpath.py	(original)
+++ python/trunk/Lib/posixpath.py	Sun Jan  6 15:27:15 2008
@@ -398,4 +398,6 @@
     i = len(commonprefix([start_list, path_list]))
 
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+    if not rel_list:
+        return curdir
     return join(*rel_list)

Modified: python/trunk/Lib/test/test_ntpath.py
==============================================================================
--- python/trunk/Lib/test/test_ntpath.py	(original)
+++ python/trunk/Lib/test/test_ntpath.py	Sun Jan  6 15:27:15 2008
@@ -166,6 +166,7 @@
 tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
 tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
 tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
+tester('ntpath.relpath("a", "a")', '.')
 
 if errors:
     raise TestFailed(str(errors) + " errors.")

Modified: python/trunk/Lib/test/test_posixpath.py
==============================================================================
--- python/trunk/Lib/test/test_posixpath.py	(original)
+++ python/trunk/Lib/test/test_posixpath.py	Sun Jan  6 15:27:15 2008
@@ -501,6 +501,7 @@
             self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
             self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
             self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
+            self.assertEqual(posixpath.relpath("a", "a"), ".")
         finally:
             os.getcwd = real_getcwd
 

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Sun Jan  6 15:27:15 2008
@@ -342,6 +342,9 @@
 Library
 -------
 
+- Bug #1742: return os.curdir from os.path.relpath() if both arguments are
+  equal instead of raising an exception.
+
 - Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
 
 - Patch #1698: allow '@' in username parsed by urlparse.py.


More information about the Python-checkins mailing list