mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
Merged revisions 61596-61597 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61596 | martin.v.loewis | 2008-03-18 23:43:46 -0500 (Di, 18 Mär 2008) | 2 lines Import lib2to3. ........ r61597 | martin.v.loewis | 2008-03-18 23:58:04 -0500 (Di, 18 Mär 2008) | 3 lines Initialized merge tracking via "svnmerge" with revisions "1-61595" from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........
This commit is contained in:
parent
c42bcbb1f0
commit
ef04c44e29
67 changed files with 11990 additions and 0 deletions
70
Lib/lib2to3/fixes/fix_renames.py
Normal file
70
Lib/lib2to3/fixes/fix_renames.py
Normal file
|
@ -0,0 +1,70 @@
|
|||
"""Fix incompatible renames
|
||||
|
||||
Fixes:
|
||||
* sys.maxint -> sys.maxsize
|
||||
"""
|
||||
# Author: Christian Heimes
|
||||
# based on Collin Winter's fix_import
|
||||
|
||||
# Local imports
|
||||
from .import basefix
|
||||
from .util import Name, attr_chain, any, set
|
||||
|
||||
MAPPING = {"sys": {"maxint" : "maxsize"},
|
||||
}
|
||||
LOOKUP = {}
|
||||
|
||||
def alternates(members):
|
||||
return "(" + "|".join(map(repr, members)) + ")"
|
||||
|
||||
|
||||
def build_pattern():
|
||||
#bare = set()
|
||||
for module, replace in MAPPING.items():
|
||||
for old_attr, new_attr in replace.items():
|
||||
LOOKUP[(module, old_attr)] = new_attr
|
||||
#bare.add(module)
|
||||
#bare.add(old_attr)
|
||||
#yield """
|
||||
# import_name< 'import' (module=%r
|
||||
# | dotted_as_names< any* module=%r any* >) >
|
||||
# """ % (module, module)
|
||||
yield """
|
||||
import_from< 'from' module_name=%r 'import'
|
||||
( attr_name=%r | import_as_name< attr_name=%r 'as' any >) >
|
||||
""" % (module, old_attr, old_attr)
|
||||
yield """
|
||||
power< module_name=%r trailer< '.' attr_name=%r > any* >
|
||||
""" % (module, old_attr)
|
||||
#yield """bare_name=%s""" % alternates(bare)
|
||||
|
||||
|
||||
class FixRenames(basefix.BaseFix):
|
||||
PATTERN = "|".join(build_pattern())
|
||||
|
||||
order = "pre" # Pre-order tree traversal
|
||||
|
||||
# Don't match the node if it's within another match
|
||||
def match(self, node):
|
||||
match = super(FixRenames, self).match
|
||||
results = match(node)
|
||||
if results:
|
||||
if any([match(obj) for obj in attr_chain(node, "parent")]):
|
||||
return False
|
||||
return results
|
||||
return False
|
||||
|
||||
#def start_tree(self, tree, filename):
|
||||
# super(FixRenames, self).start_tree(tree, filename)
|
||||
# self.replace = {}
|
||||
|
||||
def transform(self, node, results):
|
||||
mod_name = results.get("module_name")
|
||||
attr_name = results.get("attr_name")
|
||||
#bare_name = results.get("bare_name")
|
||||
#import_mod = results.get("module")
|
||||
|
||||
if mod_name and attr_name:
|
||||
new_attr = LOOKUP[(mod_name.value, attr_name.value)]
|
||||
attr_name.replace(Name(new_attr, prefix=attr_name.get_prefix()))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue