Kaydet (Commit) e511fc79 authored tarafından Ezio Melotti's avatar Ezio Melotti

#7930: fix stripid

üst 6dfe6629
...@@ -124,9 +124,7 @@ _re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE) ...@@ -124,9 +124,7 @@ _re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
def stripid(text): def stripid(text):
"""Remove the hexadecimal id from a Python object representation.""" """Remove the hexadecimal id from a Python object representation."""
# The behaviour of %p is implementation-dependent in terms of case. # 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 _re_stripid.sub(r'\1', text)
return text
def _is_some_method(obj): def _is_some_method(obj):
return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj) return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj)
......
...@@ -291,6 +291,19 @@ class PyDocDocTest(unittest.TestCase): ...@@ -291,6 +291,19 @@ class PyDocDocTest(unittest.TestCase):
"white space was not stripped from module name " "white space was not stripped from module name "
"or other error output mismatch") "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): class TestDescriptions(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment