If we can avoid the outer parenthesis of a generator function, set the node key to 'call_generator' and the caller will do the default action on that. Otherwise we do nothing.
(mapping_key, node)
| 130 | # Note: this is only used in Python > 3.0 |
| 131 | # Should move this somewhere more specific? |
| 132 | def gen_function_parens_adjust(mapping_key, node): |
| 133 | """If we can avoid the outer parenthesis |
| 134 | of a generator function, set the node key to |
| 135 | 'call_generator' and the caller will do the default |
| 136 | action on that. Otherwise we do nothing. |
| 137 | """ |
| 138 | if mapping_key.kind != 'CALL_FUNCTION_1': |
| 139 | return |
| 140 | |
| 141 | args_node = node[-2] |
| 142 | if args_node == 'pos_arg': |
| 143 | assert args_node[0] == 'expr' |
| 144 | n = args_node[0][0] |
| 145 | if n == 'generator_exp': |
| 146 | node.kind = 'call_generator' |
| 147 | pass |
| 148 | return |
| 149 | |
| 150 | def is_lambda_mode(compile_mode: str) -> bool: |
| 151 | return compile_mode in ("dictcomp", "genexpr", "lambda", "listcomp", "setcomp") |