[ python-Bugs-1234985 ] using some_re.sub() often imports sre.__doc__

SourceForge.net noreply at sourceforge.net
Fri Jul 8 23:46:21 CEST 2005


Bugs item #1234985, was opened at 2005-07-09 00:46
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1234985&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Regular Expressions
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Steve Alexander (stevea_zope)
Assigned to: Gustavo Niemeyer (niemeyer)
Summary: using some_re.sub() often imports sre.__doc__

Initial Comment:
Why is __doc__ imported from the builtin sre module
when a regular expression is substituted replacing a group?


$ python
Python 2.4.1 (#2, Mar 30 2005, 21:51:10)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.

>>> def import_hook(name, globals={}, locals={},
fromlist=[]):
...     print name, fromlist
...     return original_import(name, globals, locals,
fromlist)
...
>>> import __builtin__
>>> original_import = __builtin__.__import__
>>> __builtin__.__import__ = import_hook

>>> import re
re None
sre ('*',)
sys None
sre_compile None
_sre None
sys None
sre_constants ('*',)
sre_parse None
sys None
sre_constants ('*',)
sre_parse None
copy_reg None
sre ('__all__',)

>>> re1 = re.compile('foo...bar')
sre_parse None

>>> re1.sub('x', 'y')
'y'
>>> re1.sub('x', 'fooXXXbar')
'x'

>>> re2 = re.compile('foo(...)bar')
sre_parse None
>>> re2.sub('x', 'y')
'y'
>>> re2.sub('\1', 'fooXXXbar')
sre ['__doc__']
'XXX'


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1234985&group_id=5470


More information about the Python-bugs-list mailing list