2016-04-01 21:01:32 +02:00
|
|
|
import re
|
2016-04-01 12:00:08 +02:00
|
|
|
|
2016-04-01 21:01:32 +02:00
|
|
|
from lib2to3.fixer_util import Leaf, Node, find_indentation, syms
|
2024-11-29 14:26:30 +01:00
|
|
|
|
2016-04-01 12:00:08 +02:00
|
|
|
from libfuturize.fixes.fix_print_with_import import (
|
|
|
|
FixPrintWithImport as FixPrintWithImportOrig,
|
2024-11-29 14:26:30 +01:00
|
|
|
)
|
|
|
|
|
2016-04-03 01:42:37 +02:00
|
|
|
|
2016-04-01 12:00:08 +02:00
|
|
|
class FixPrintWithImport(FixPrintWithImportOrig):
|
|
|
|
|
2016-04-01 21:01:32 +02:00
|
|
|
def transform(self, node, results):
|
|
|
|
if "fix_print_with_import" in node.prefix:
|
|
|
|
return node
|
2016-04-01 12:00:08 +02:00
|
|
|
|
2023-02-01 09:54:38 +01:00
|
|
|
r = super().transform(node, results)
|
2016-04-01 21:01:32 +02:00
|
|
|
|
|
|
|
if not r or r == node:
|
|
|
|
return r
|
|
|
|
|
|
|
|
if not r.prefix:
|
|
|
|
indentation = find_indentation(node)
|
|
|
|
r.prefix = "# fix_print_with_import\n" + indentation
|
|
|
|
else:
|
|
|
|
r.prefix = re.sub("([ \t]*$)", r"\1# fix_print_with_import\n\1", r.prefix)
|
|
|
|
|
|
|
|
return r
|