This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pydoc.stripid doesn't strip ID
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, jimjjewett, rgbecker, theller, tim.peters
Priority: normal Keywords:

Created on 2004-04-13 15:32 by jimjjewett, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg20491 - (view) Author: Jim Jewett (jimjjewett) Date: 2004-04-13 15:32
pydoc function stripid should strip the ID from an object's 
repr.  It assumes that ID will be represented as one of 
two patterns -- but this is not the case with (at least) 
the 2.3.3 distributed binary, because of case-sensitivity.

' at 0x[0-9a-f]{6,}(>+)$' 
fails because the address is capitalized -- A-F.  (Note 
that hex(15) is not capitalized -- this seems to be unique 
to addresses.)

' at [0-9A-F]{8,}(>+)$'
fails because the address does contain a 0x.

stripid checks both as a guard against false alarms, but 
I'm not sure how to guarantee that an address would 
contain a letter, so matching on either all-upper or 
all-lower may be the tightest possible bound.

msg20492 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2004-04-14 19:34
Logged In: YES 
user_id=11105

It seems this depends on the operating system, more exactly
on how the C compiler interprets the %p printf format.
According to what I see, on windows it fails, on linux it works.
msg20493 - (view) Author: Robin Becker (rgbecker) Date: 2004-06-05 15:36
Logged In: YES 
user_id=6946

Definitely a problem in 2.3.3.

using
class bongo: pass
print bongo()

On freebsd with 2.3.3 I get
<__main__.bongo instance at 0x81a05ac>

with win2k I see
<__main__.bongo instance at 0x0112FFD0>

both are 8 characters, but the case differs.
msg20494 - (view) Author: Robin Becker (rgbecker) Date: 2004-06-05 16:23
Logged In: YES 
user_id=6946

This patch seems to fix variable case problems
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.90
diff -c -r1.90 pydoc.py
*** pydoc.py    29 Jan 2004 06:37:49 -0000      1.90
--- pydoc.py    5 Jun 2004 15:26:31 -0000
***************
*** 113,124 ****
          return text[:pre] + '...' + text[len(text)-post:]
      return text

  def stripid(text):
      """Remove the hexadecimal id from a Python object
representation."""
      # The behaviour of %p is implementation-dependent; we
check two cases.
!     for pattern in [' at 0x[0-9a-f]{6,}(>+)$', ' at
[0-9A-F]{8,}(>+)$']:
!         if re.search(pattern, repr(Exception)):
!             return re.sub(pattern, '\\1', text)
      return text

  def _is_some_method(object):
--- 113,124 ----
          return text[:pre] + '...' + text[len(text)-post:]
      return text

+ _re_stripid =re.compile(' at
(?:0[xX][0-9a-fA-F]{6,}|[0-9a-fA-F]{8,})(>+)$']
  def stripid(text):
      """Remove the hexadecimal id from a Python object
representation."""
      # The behaviour of %p is implementation-dependent; we
check two cases.
!     if _re_stripid.search(repr(Exception)):
!         return _re_stripid.sub('\\1', text)
      return text

  def _is_some_method(object):
msg20495 - (view) Author: Robin Becker (rgbecker) Date: 2004-06-05 16:31
Logged In: YES 
user_id=6946

This is the PROPER pasted in patch

===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.90
diff -c -r1.90 pydoc.py
*** pydoc.py    29 Jan 2004 06:37:49 -0000      1.90
--- pydoc.py    5 Jun 2004 15:33:52 -0000
***************
*** 113,124 ****
          return text[:pre] + '...' + text[len(text)-post:]
      return text

  def stripid(text):
      """Remove the hexadecimal id from a Python object
representation."""
      # The behaviour of %p is implementation-dependent; we
check two cases.
!     for pattern in [' at 0x[0-9a-f]{6,}(>+)$', ' at
[0-9A-F]{8,}(>+)$']:
!         if re.search(pattern, repr(Exception)):
!             return re.sub(pattern, '\\1', text)
      return text

  def _is_some_method(object):
--- 113,124 ----
          return text[:pre] + '...' + text[len(text)-post:]
      return text

+ _re_stripid =re.compile(' at
(?:0[xX][0-9a-fA-F]{6,}|[0-9a-fA-F]{8,})(>+)$')
  def stripid(text):
      """Remove the hexadecimal id from a Python object
representation."""
      # The behaviour of %p is implementation-dependent; we
check two cases.
!     if _re_stripid.search(repr(Exception)):
!         return _re_stripid.sub('\\1', text)
      return text

  def _is_some_method(object):
msg20496 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-06-05 17:05
Logged In: YES 
user_id=31435

This can be simplifed.  The code in PyString_FromFormatV() 
massages the native %p result to guarantee it begins 
with "0x".  It didn't always do this, and inspect.py was 
written when Python didn't massage the native %p result at 
all.  Now there's no need to cater to "0X", or to cater to 
that "0x" might be missing.  The case of a-f may still differ 
across platforms, and that's deliberate (addresses are of 
most interest to C coders, and they're "used to" whichever 
case their platform delivers for %p in C code).
msg20497 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2004-06-19 01:24
Logged In: YES 
user_id=357491

OK, I took Robin's idea of extracting out the regex, but just made it case-
insensitive with re.IGNORECASE.  Also ripped out dealing with the case 
lacking '0x' thanks to Tim's tip.  Finally, I changed the match length from 
6 to 6-16 to be able to handle 64-bit addresses (only in 2.4 since I could 
be wrong).

Checked in as rev. 1.93 in HEAD and rev. 1.86.8.2 in 2.3 .  Thanks, 
Robin.
msg20498 - (view) Author: Jim Jewett (jimjjewett) Date: 2004-06-21 14:11
Logged In: YES 
user_id=764593

Using ignorecase means it will also select mixed-case, such as 
0xDead86.  Given that 0x is now required, that might actually 
be desirable, but it is a change.

History
Date User Action Args
2022-04-11 14:56:03adminsetgithub: 40144
2004-04-13 15:32:29jimjjewettcreate