Make sure the brackets are set properly

This commit is contained in:
Dave Halter
2020-02-14 17:08:42 +01:00
parent d536a20019
commit af20905f7d

View File

@@ -7,6 +7,11 @@ from parso import split_lines
from jedi.api.exceptions import RefactoringError from jedi.api.exceptions import RefactoringError
_INLINE_NEEDS_BRACKET = (
'xor_expr and_expr shift_expr arith_expr term factor power '
'or_test and_test not_test comparison'
).split()
class ChangedFile(object): class ChangedFile(object):
def __init__(self, grammar, from_path, to_path, module_node, node_to_str_map): def __init__(self, grammar, from_path, to_path, module_node, node_to_str_map):
@@ -178,7 +183,8 @@ def inline(grammar, names):
for name in references: for name in references:
path = name.get_root_context().py__file__() path = name.get_root_context().py__file__()
s = replace_code s = replace_code
if rhs.type == 'testlist_star_expr': if rhs.type == 'testlist_star_expr' \
or name.tree_name.parent.type in _INLINE_NEEDS_BRACKET:
s = '(' + replace_code + ')' s = '(' + replace_code + ')'
file_to_node_changes.setdefault(path, {})[name.tree_name] = \ file_to_node_changes.setdefault(path, {})[name.tree_name] = \
name.tree_name.prefix + s name.tree_name.prefix + s