]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 78207 via svnmerge from
authorEzio Melotti <ezio.melotti@gmail.com>
Tue, 16 Feb 2010 23:29:44 +0000 (23:29 +0000)
committerEzio Melotti <ezio.melotti@gmail.com>
Tue, 16 Feb 2010 23:29:44 +0000 (23:29 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line

  #7930: fix stripid
........

Lib/pydoc.py
Lib/test/test_pydoc.py

index 4cf9066caa36107510cfb19ba1ff8c3d24517c8e..e9832126d026e9618d132024e8628b0b4c1a2430 100755 (executable)
@@ -124,9 +124,7 @@ _re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
 def stripid(text):
     """Remove the hexadecimal id from a Python object representation."""
     # The behaviour of %p is implementation-dependent in terms of case.
-    if _re_stripid.search(repr(Exception)):
-        return _re_stripid.sub(r'\1', text)
-    return text
+    return _re_stripid.sub(r'\1', text)
 
 def _is_some_method(obj):
     return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj)
index ea66d262eac3c41e9e06a63968c09fe4abc686de..168c4d135a401b0d39d7aa16dd98138d107d6817 100644 (file)
@@ -288,6 +288,19 @@ class PyDocDocTest(unittest.TestCase):
             "white space was not stripped from module name "
             "or other error output mismatch")
 
+    def test_stripid(self):
+        # test with strings, other implementations might have different repr()
+        stripid = pydoc.stripid
+        # strip the id
+        self.assertEqual(stripid('<function stripid at 0x88dcee4>'),
+                         '<function stripid>')
+        self.assertEqual(stripid('<function stripid at 0x01F65390>'),
+                         '<function stripid>')
+        # nothing to strip, return the same text
+        self.assertEqual(stripid('42'), '42')
+        self.assertEqual(stripid("<type 'exceptions.Exception'>"),
+                         "<type 'exceptions.Exception'>")
+
 
 class TestDescriptions(unittest.TestCase):