1
"""Fixer that addes parentheses where they are required
3
This converts ``[x for x in 1, 2]`` to ``[x for x in (1, 2)]``."""
5
# By Taek Joo Kim and Benjamin Peterson
8
from .. import fixer_base
9
from ..fixer_util import LParen, RParen
11
# XXX This doesn't support nested for loops like [x for x in 1, 2 for x in 1, 2]
12
class FixParen(fixer_base.BaseFix):
18
target=testlist_safe< any (',' any)+ [',']
27
target=testlist_safe< any (',' any)+ [',']
35
def transform(self, node, results):
36
target = results["target"]
39
lparen.set_prefix(target.get_prefix())
40
target.set_prefix("") # Make it hug the parentheses
41
target.insert_child(0, lparen)
42
target.append_child(RParen())