]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
authorGeorg Brandl <georg@python.org>
Sun, 6 Jan 2008 14:27:15 +0000 (14:27 +0000)
committerGeorg Brandl <georg@python.org>
Sun, 6 Jan 2008 14:27:15 +0000 (14:27 +0000)
Reported by Jesse Towner.

Lib/ntpath.py
Lib/posixpath.py
Lib/test/test_ntpath.py
Lib/test/test_posixpath.py
Misc/NEWS

index fa2fc29970d9e0fe25a416cadff71881b5cb670b..c4a4ac5f70593cea8307a3df1f52f2807bf28ada 100644 (file)
@@ -490,4 +490,6 @@ def relpath(path, start=curdir):
         i += 1
 
     rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
+    if not rel_list:
+        return curdir
     return join(*rel_list)
index ee763ad25457cc06ee0db08187221edcbefac2c0..ee6d0f2407ab8e09d8ba9cda0a1c404e4df3de0e 100644 (file)
@@ -398,4 +398,6 @@ def relpath(path, start=curdir):
     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)
index 6af9c851423d7efcb987e9c457140b7b8732254b..4c9a0c2f768cdbea7375ea52225e4321111098d9 100644 (file)
@@ -166,6 +166,7 @@ tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
 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.")
index 88aa68c5b3caa7c07fbcfb4e02984f9f5b777ab5..46ac067263102e2d6f4b2a6f5d5f0e8b26c74eb6 100644 (file)
@@ -501,6 +501,7 @@ class PosixPathTest(unittest.TestCase):
             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
 
index cf54566a3eeb0e4b565e48b36e87b14877edfc32..473211397329be0c3d7bac8c29025135ab23aa58 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -342,6 +342,9 @@ Core and builtins
 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.