summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-08-15 23:56:02 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-08-15 23:56:02 (GMT)
commit24c4d85598d9f191350ae8a345c310a1a5c75214 (patch)
tree3834cbd695ed3617b94d08c53e83ce12cc68821d /Lib/lib2to3
parentdeb75f579b597d996734f66f93a2303bc7ac4fab (diff)
downloadcpython-24c4d85598d9f191350ae8a345c310a1a5c75214.zip
cpython-24c4d85598d9f191350ae8a345c310a1a5c75214.tar.gz
cpython-24c4d85598d9f191350ae8a345c310a1a5c75214.tar.bz2
Merged revisions 65703 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ................ r65703 | benjamin.peterson | 2008-08-15 18:51:24 -0500 (Fri, 15 Aug 2008) | 11 lines Merged revisions 65397 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r65397 | collin.winter | 2008-08-01 22:39:06 -0500 (Fri, 01 Aug 2008) | 5 lines Patch #3480 by Nick Edds. Dramatically simplifies the fix_imports pattern, resulting in a reduction of the test_all_fixers runtime from 122+ secs to 59 secs (a good predictor of 2to3 performance). ........ ................
Diffstat (limited to 'Lib/lib2to3')
-rw-r--r--Lib/lib2to3/fixes/fix_imports.py35
1 files changed, 17 insertions, 18 deletions
diff --git a/Lib/lib2to3/fixes/fix_imports.py b/Lib/lib2to3/fixes/fix_imports.py
index fc1d7bb..e7e7a75 100644
--- a/Lib/lib2to3/fixes/fix_imports.py
+++ b/Lib/lib2to3/fixes/fix_imports.py
@@ -61,24 +61,23 @@ def alternates(members):
def build_pattern(mapping=MAPPING):
- bare = set()
- for old_module, new_module in mapping.items():
- bare.add(old_module)
- yield """import_name< 'import' (module=%r
- | dotted_as_names< any* module=%r any* >) >
- """ % (old_module, old_module)
- yield """import_from< 'from' module_name=%r 'import'
- ( any | import_as_name< any 'as' any > |
- import_as_names< any* >) >
- """ % old_module
- yield """import_name< 'import'
- dotted_as_name< module_name=%r 'as' any > >
- """ % old_module
- # Find usages of module members in code e.g. urllib.foo(bar)
- yield """power< module_name=%r
- trailer<'.' any > any* >
- """ % old_module
- yield """bare_name=%s""" % alternates(bare)
+ mod_list = ' | '.join(["module='" + key + "'" for key in mapping.keys()])
+ mod_name_list = ' | '.join(["module_name='" + key + "'" for key in mapping.keys()])
+ yield """import_name< 'import' ((%s)
+ | dotted_as_names< any* (%s) any* >) >
+ """ % (mod_list, mod_list)
+ yield """import_from< 'from' (%s) 'import'
+ ( any | import_as_name< any 'as' any > |
+ import_as_names< any* >) >
+ """ % mod_name_list
+ yield """import_name< 'import'
+ dotted_as_name< (%s) 'as' any > >
+ """ % mod_name_list
+ # Find usages of module members in code e.g. urllib.foo(bar)
+ yield """power< (%s)
+ trailer<'.' any > any* >
+ """ % mod_name_list
+ yield """bare_name=%s""" % alternates(mapping.keys())
class FixImports(fixer_base.BaseFix):
PATTERN = "|".join(build_pattern())