]> granicus.if.org Git - python/commitdiff
#7930: fix stripid
authorEzio Melotti <ezio.melotti@gmail.com>
Tue, 16 Feb 2010 23:26:09 +0000 (23:26 +0000)
committerEzio Melotti <ezio.melotti@gmail.com>
Tue, 16 Feb 2010 23:26:09 +0000 (23:26 +0000)
Lib/pydoc.py
Lib/test/test_pydoc.py

index 7da75b65bf0fb95f5d6dd659c92a94cc5736ed20..7a55023319ec447435bba3cc536d8418eea40ea5 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 89f1c22236ea6e5a0d5de24fa18b6723aba8b5b0..5f2d3b33d94efdafa6034aa7717dffb8a42b80c2 100644 (file)
@@ -291,6 +291,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):