[Python-bugs-list] [Bug #125808] Fiddling builtin str flips out re.sub

noreply@sourceforge.net noreply@sourceforge.net
Thu, 14 Dec 2000 09:40:36 -0800


Bug #125808, was updated on 2000-Dec-14 09:40
Here is a current snapshot of the bug.

Project: Python
Category: None
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: montanaro
Assigned to : nobody
Summary: Fiddling builtin str flips out re.sub

Details: Something about replacing __builtin__.str seems to cause re.sub to fail when trying to replace control characters in a string.  Given the following PYTHONSTARTUP file:

import pprint, __builtin__
class Writer:
    def __init__(self):
        self.pp = pprint.PrettyPrinter()

    def str(self, obj):
        return self.pp.pformat(obj)
__builtin__.str = Writer().str


executing the following at an interactive Python prompt:

    import re ; re.sub(r"[\000-\037\177]", "", "\000")

causes the substitution to fail.  This is with a version of Python compiled from the latest CVS tree.  It also fails with 2.0c1, but not 1.5.2.


For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=125808&group_id=5470