Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24c4d85

Browse files
committed
Merged revisions 65703 via svnmerge from
svn+ssh://[email protected]/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://[email protected]/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). ........ ................
1 parent deb75f5 commit 24c4d85

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

Lib/lib2to3/fixes/fix_imports.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,23 @@ def alternates(members):
6161

6262

6363
def build_pattern(mapping=MAPPING):
64-
bare = set()
65-
for old_module, new_module in mapping.items():
66-
bare.add(old_module)
67-
yield """import_name< 'import' (module=%r
68-
| dotted_as_names< any* module=%r any* >) >
69-
""" % (old_module, old_module)
70-
yield """import_from< 'from' module_name=%r 'import'
71-
( any | import_as_name< any 'as' any > |
72-
import_as_names< any* >) >
73-
""" % old_module
74-
yield """import_name< 'import'
75-
dotted_as_name< module_name=%r 'as' any > >
76-
""" % old_module
77-
# Find usages of module members in code e.g. urllib.foo(bar)
78-
yield """power< module_name=%r
79-
trailer<'.' any > any* >
80-
""" % old_module
81-
yield """bare_name=%s""" % alternates(bare)
64+
mod_list = ' | '.join(["module='" + key + "'" for key in mapping.keys()])
65+
mod_name_list = ' | '.join(["module_name='" + key + "'" for key in mapping.keys()])
66+
yield """import_name< 'import' ((%s)
67+
| dotted_as_names< any* (%s) any* >) >
68+
""" % (mod_list, mod_list)
69+
yield """import_from< 'from' (%s) 'import'
70+
( any | import_as_name< any 'as' any > |
71+
import_as_names< any* >) >
72+
""" % mod_name_list
73+
yield """import_name< 'import'
74+
dotted_as_name< (%s) 'as' any > >
75+
""" % mod_name_list
76+
# Find usages of module members in code e.g. urllib.foo(bar)
77+
yield """power< (%s)
78+
trailer<'.' any > any* >
79+
""" % mod_name_list
80+
yield """bare_name=%s""" % alternates(mapping.keys())
8281

8382
class FixImports(fixer_base.BaseFix):
8483
PATTERN = "|".join(build_pattern())

0 commit comments

Comments
 (0)