#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index fa2fc29..c4a4ac5 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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)
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index ee763ad..ee6d0f2 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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)
diff --git a/Lib/test/test_ntpath.py b/Lib/test/test_ntpath.py
index 6af9c85..4c9a0c2 100644
--- a/Lib/test/test_ntpath.py
+++ b/Lib/test/test_ntpath.py
@@ -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.")
diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py
index 88aa68c..46ac067 100644
--- a/Lib/test/test_posixpath.py
+++ b/Lib/test/test_posixpath.py
@@ -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
 
diff --git a/Misc/NEWS b/Misc/NEWS
index cf54566..4732113 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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.