fix_add_all_future_builtins.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. For the ``future`` package.
  3. Adds this import line::
  4. from builtins import (ascii, bytes, chr, dict, filter, hex, input,
  5. int, list, map, next, object, oct, open, pow,
  6. range, round, str, super, zip)
  7. to a module, irrespective of whether each definition is used.
  8. Adds these imports after any other imports (in an initial block of them).
  9. """
  10. from __future__ import unicode_literals
  11. from lib2to3 import fixer_base
  12. from libfuturize.fixer_util import touch_import_top
  13. class FixAddAllFutureBuiltins(fixer_base.BaseFix):
  14. BM_compatible = True
  15. PATTERN = "file_input"
  16. run_order = 1
  17. def transform(self, node, results):
  18. # import_str = """(ascii, bytes, chr, dict, filter, hex, input,
  19. # int, list, map, next, object, oct, open, pow,
  20. # range, round, str, super, zip)"""
  21. touch_import_top(u'builtins', '*', node)
  22. # builtins = """ascii bytes chr dict filter hex input
  23. # int list map next object oct open pow
  24. # range round str super zip"""
  25. # for builtin in sorted(builtins.split(), reverse=True):
  26. # touch_import_top(u'builtins', builtin, node)