changeset 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from 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 ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 15b049fac191
children 9a581c0210f2
files Lib/pydoc.py Lib/test/test_pydoc.py
diffstat 2 files changed, 14 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Lib/pydoc.py	Mon Feb 15 21:43:41 2010 +0000
+++ b/Lib/pydoc.py	Tue Feb 16 23:29:44 2010 +0000
@@ -124,9 +124,7 @@
 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)
--- a/Lib/test/test_pydoc.py	Mon Feb 15 21:43:41 2010 +0000
+++ b/Lib/test/test_pydoc.py	Tue Feb 16 23:29:44 2010 +0000
@@ -288,6 +288,19 @@
             "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):