From 5f943ed1338f9c4df4602c0d64faf4e34eebe708 Mon Sep 17 00:00:00 2001 From: Ezio Melotti Date: Tue, 16 Feb 2010 23:29:44 +0000 Subject: [PATCH] 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 ........ --- Lib/pydoc.py | 4 +--- Lib/test/test_pydoc.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 4cf9066caa3..e9832126d02 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 ea66d262eac..168c4d135a4 100644 --- a/Lib/test/test_pydoc.py +++ b/Lib/test/test_pydoc.py @@ -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(''), + '') + self.assertEqual(stripid(''), + '') + # nothing to strip, return the same text + self.assertEqual(stripid('42'), '42') + self.assertEqual(stripid(""), + "") + class TestDescriptions(unittest.TestCase):