fix_print_with_import.py 735 B

12345678910111213141516171819202122
  1. """
  2. For the ``future`` package.
  3. Turns any print statements into functions and adds this import line:
  4. from __future__ import print_function
  5. at the top to retain compatibility with Python 2.6+.
  6. """
  7. from libfuturize.fixes.fix_print import FixPrint
  8. from libfuturize.fixer_util import future_import
  9. class FixPrintWithImport(FixPrint):
  10. run_order = 7
  11. def transform(self, node, results):
  12. # Add the __future__ import first. (Otherwise any shebang or encoding
  13. # comment line attached as a prefix to the print statement will be
  14. # copied twice and appear twice.)
  15. future_import(u'print_function', node)
  16. n_stmt = super(FixPrintWithImport, self).transform(node, results)
  17. return n_stmt