openmedialibrary_platform_d.../lib/python3.7/lib2to3/fixes/fix_input.py

27 lines
708 B
Python
Raw Normal View History

2016-02-06 09:36:57 +00:00
"""Fixer that changes input(...) into eval(input(...))."""
# Author: Andre Roberge
# Local imports
from .. import fixer_base
from ..fixer_util import Call, Name
from .. import patcomp
context = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >")
class FixInput(fixer_base.BaseFix):
BM_compatible = True
PATTERN = """
power< 'input' args=trailer< '(' [any] ')' > >
"""
def transform(self, node, results):
2018-12-31 23:25:26 +00:00
# If we're already wrapped in an eval() call, we're done.
2016-02-06 09:36:57 +00:00
if context.match(node.parent.parent):
return
new = node.clone()
new.prefix = ""
return Call(Name("eval"), [new], prefix=node.prefix)