From: Ezio Melotti Date: Tue, 16 Feb 2010 23:26:09 +0000 (+0000) Subject: #7930: fix stripid X-Git-Tag: v2.7a4~182 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e511fc7979b21a62edf3f85d4eecdc8a9ea2f06a;p=python #7930: fix stripid --- diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 7da75b65bf..7a55023319 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -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) diff --git a/Lib/test/test_pydoc.py b/Lib/test/test_pydoc.py index 89f1c22236..5f2d3b33d9 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -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(''), + '') + self.assertEqual(stripid(''), + '') + # nothing to strip, return the same text + self.assertEqual(stripid('42'), '42') + self.assertEqual(stripid(""), + "") + class TestDescriptions(unittest.TestCase):