DRY x0ret's code a little bit.

This commit is contained in:
rocky
2019-06-05 20:14:04 -04:00
parent fd59879510
commit cb40caa73c
5 changed files with 45 additions and 42 deletions

View File

@@ -196,6 +196,26 @@ def flatten_list(node):
pass
return flat_elems
# Note: this is only used in Python > 3.0
# Should move this somewhere more specific?
def gen_function_parens_adjust(mapping_key, node):
"""If we can avoid the outer parenthesis
of a generator function, set the node key to
'generator_no_parens' and the caller will do the default
action on that. Otherwise we do nothing.
"""
if mapping_key.kind != 'CALL_FUNCTION_1':
return
args_node = node[-2]
if args_node == 'pos_arg':
assert args_node[0] == 'expr'
n = args_node[0][0]
if n == 'generator_exp':
node.kind = 'generator_no_parens'
pass
return
# if __name__ == '__main__':
# if PYTHON3: