fix_xrange_with_import.py 479 B

1234567891011121314151617181920
  1. """
  2. For the ``future`` package.
  3. Turns any xrange calls into range calls and adds this import line:
  4. from builtins import range
  5. at the top.
  6. """
  7. from lib2to3.fixes.fix_xrange import FixXrange
  8. from libfuturize.fixer_util import touch_import_top
  9. class FixXrangeWithImport(FixXrange):
  10. def transform(self, node, results):
  11. result = super(FixXrangeWithImport, self).transform(node, results)
  12. touch_import_top('builtins', 'range', node)
  13. return result