New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using some_re.sub() often imports sre.__doc__ #42177
Comments
Why is __doc__ imported from the builtin sre module $ 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' |
Logged In: YES This is significant for programs that use an expensive I'm working around this by making my import hook return |
Logged In: YES Below is the full source of re.py. Does your problem go away """Minimal "re" compatibility wrapper. See "sre" for engine = "sre" # Some apps might use this undocumented variable
from sre import *
from sre import __all__ |
pattern.sub() imports the SRE Python module (to call its subx()) with The import of an additional module is gone now that re is really called re. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: