fix_input.py 687 B

1234567891011121314151617181920212223242526272829303132
  1. """
  2. Fixer for input.
  3. Does a check for `from builtins import input` before running the lib2to3 fixer.
  4. The fixer will not run when the input is already present.
  5. this:
  6. a = input()
  7. becomes:
  8. from builtins import input
  9. a = eval(input())
  10. and this:
  11. from builtins import input
  12. a = input()
  13. becomes (no change):
  14. from builtins import input
  15. a = input()
  16. """
  17. import lib2to3.fixes.fix_input
  18. from lib2to3.fixer_util import does_tree_import
  19. class FixInput(lib2to3.fixes.fix_input.FixInput):
  20. def transform(self, node, results):
  21. if does_tree_import('builtins', 'input', node):
  22. return
  23. return super(FixInput, self).transform(node, results)