Issue #1515: Enable use of deepcopy() with instance methods. Patch by Robert Collins.
[python.git] / Lib / lib2to3 / fixes / fix_paren.py
blobeeb0d4070a07411b0b097a68d61bf6429d55f954
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
7 # Local imports
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):
13 PATTERN = """
14 atom< ('[' | '(')
15 (listmaker< any
16 comp_for<
17 'for' NAME 'in'
18 target=testlist_safe< any (',' any)+ [',']
20 [any]
24 testlist_gexp< any
25 comp_for<
26 'for' NAME 'in'
27 target=testlist_safe< any (',' any)+ [',']
29 [any]
32 (']' | ')') >
33 """
35 def transform(self, node, results):
36 target = results["target"]
38 lparen = LParen()
39 lparen.prefix = target.prefix
40 target.prefix = u"" # Make it hug the parentheses
41 target.insert_child(0, lparen)
42 target.append_child(RParen())