fix_input.py 708 B

1234567891011121314151617181920212223242526
  1. """Fixer that changes input(...) into eval(input(...))."""
  2. # Author: Andre Roberge
  3. # Local imports
  4. from .. import fixer_base
  5. from ..fixer_util import Call, Name
  6. from .. import patcomp
  7. context = patcomp.compile_pattern("power< 'eval' trailer< '(' any ')' > >")
  8. class FixInput(fixer_base.BaseFix):
  9. BM_compatible = True
  10. PATTERN = """
  11. power< 'input' args=trailer< '(' [any] ')' > >
  12. """
  13. def transform(self, node, results):
  14. # If we're already wrapped in an eval() call, we're done.
  15. if context.match(node.parent.parent):
  16. return
  17. new = node.clone()
  18. new.prefix = ""
  19. return Call(Name("eval"), [new], prefix=node.prefix)