classification
Title: pydoc.stripid doesn't strip ID in py25, py26, py31
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ezio.melotti, georg.brandl, mnewman
Priority: normal Keywords: easy, needs review, patch

Created on 2010-02-14 23:01 by mnewman, last changed 2010-02-16 23:35 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
issue7930.patch ezio.melotti, 2010-02-16 06:42 patch for trunk + tests
Messages (5)
msg99349 - (view) Author: Michael Newman (mnewman) Date: 2010-02-14 23:01
I found that pydoc.stripid doesn't strip the ID in Python 2.5, 2.6, and 3.1. I assume the problem is probably present in 2.7 and 3.2/dev.

For a little history, see this older issue back for Python 2.3:
http://bugs.python.org/issue934282

The following example show "pydoc.stripid" works for Python 2.3 and 2.4, but then fails for versions after that.

Python 2.3.5 (#62, Feb  8 2005, 16:23:02) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydoc
>>> pydoc.stripid
<function stripid at 0x00AC0BB0>
>>> pydoc.stripid(repr(pydoc.stripid))
'<function stripid>'

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydoc
>>> pydoc.stripid
<function stripid at 0x00BB7BF0>
>>> pydoc.stripid(repr(pydoc.stripid))
'<function stripid>'

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydoc
>>> pydoc.stripid
<function stripid at 0x00BEFCF0>
>>> pydoc.stripid(repr(pydoc.stripid))
'<function stripid at 0x00BEFCF0>'

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydoc
>>> pydoc.stripid
<function stripid at 0x00C655B0>
>>> pydoc.stripid(repr(pydoc.stripid))
'<function stripid at 0x00C655B0>'

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydoc
>>> pydoc.stripid
<function stripid at 0x00CFB8A0>
>>> pydoc.stripid(repr(pydoc.stripid))
'<function stripid at 0x00CFB8A0>'
msg99356 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-15 09:42
This is the stripid implementation:

_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

The problem is that repr(Exception) used to return <class exceptions.Exception at 0x00A64510> on Py<=2.4 but now returns <type 'exceptions.Exception'>, so the code inside the if is never executed (this is what happens where there are no unittests).
That 'if' has been introduced in r19750 and I think that the reason is to check if the id in 'text' is really an id and hence has the same format of the ids of other objects. I don't think this is really necessary though.
msg99388 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-16 06:42
Here's a patch with a minimal unittest.
msg99444 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-02-16 22:28
Looks good.
msg99450 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-02-16 23:35
Fixed in r78207 (trunk), r78208 (release26-maint), r78209 (py3k) and r78210 (release31-maint).
After a short discussion on #python-dev I decided to remove the 'if', because it's not necessary and might creates problems with other implementations.
History
Date User Action Args
2010-02-16 23:35:15ezio.melottisetstatus: open -> closed
resolution: fixed
messages: + msg99450

stage: patch review -> resolved
2010-02-16 22:28:18georg.brandlsetnosy: + georg.brandl
messages: + msg99444
2010-02-16 06:42:17ezio.melottisetfiles: + issue7930.patch
versions: - Python 2.5
messages: + msg99388

keywords: + patch, easy, needs review
stage: test needed -> patch review
2010-02-15 09:42:22ezio.melottisetpriority: normal

nosy: + ezio.melotti
messages: + msg99356

assignee: ezio.melotti
stage: test needed
2010-02-14 23:01:48mnewmancreate