diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 28d3bb8c5fb..79fb54a51d7 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -123,9 +123,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 3bcd592bac6..5d99e432035 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -306,6 +306,19 @@ class PyDocDocTest(unittest.TestCase): expected = missing_pattern % missing_module.strip() self.assertEqual(expected, result) + 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):