Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3..../lib2to3/fixes
File: fix_paren.py
"""Fixer that addes parentheses where they are required
[0] Fix | Delete
[1] Fix | Delete
This converts ``[x for x in 1, 2]`` to ``[x for x in (1, 2)]``."""
[2] Fix | Delete
[3] Fix | Delete
# By Taek Joo Kim and Benjamin Peterson
[4] Fix | Delete
[5] Fix | Delete
# Local imports
[6] Fix | Delete
from .. import fixer_base
[7] Fix | Delete
from ..fixer_util import LParen, RParen
[8] Fix | Delete
[9] Fix | Delete
# XXX This doesn't support nested for loops like [x for x in 1, 2 for x in 1, 2]
[10] Fix | Delete
class FixParen(fixer_base.BaseFix):
[11] Fix | Delete
BM_compatible = True
[12] Fix | Delete
[13] Fix | Delete
PATTERN = """
[14] Fix | Delete
atom< ('[' | '(')
[15] Fix | Delete
(listmaker< any
[16] Fix | Delete
comp_for<
[17] Fix | Delete
'for' NAME 'in'
[18] Fix | Delete
target=testlist_safe< any (',' any)+ [',']
[19] Fix | Delete
>
[20] Fix | Delete
[any]
[21] Fix | Delete
>
[22] Fix | Delete
>
[23] Fix | Delete
|
[24] Fix | Delete
testlist_gexp< any
[25] Fix | Delete
comp_for<
[26] Fix | Delete
'for' NAME 'in'
[27] Fix | Delete
target=testlist_safe< any (',' any)+ [',']
[28] Fix | Delete
>
[29] Fix | Delete
[any]
[30] Fix | Delete
>
[31] Fix | Delete
>)
[32] Fix | Delete
(']' | ')') >
[33] Fix | Delete
"""
[34] Fix | Delete
[35] Fix | Delete
def transform(self, node, results):
[36] Fix | Delete
target = results["target"]
[37] Fix | Delete
[38] Fix | Delete
lparen = LParen()
[39] Fix | Delete
lparen.prefix = target.prefix
[40] Fix | Delete
target.prefix = "" # Make it hug the parentheses
[41] Fix | Delete
target.insert_child(0, lparen)
[42] Fix | Delete
target.append_child(RParen())
[43] Fix | Delete
[44] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function