-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
Description
generator expression must be parenthesized
Regardless of whether there is a trailing comma or not, the exact same AST is generated by ruff for the code (only the ranges are different).
Given this, how do we detect the trailing comma during the semantic syntax error phase?
Should this rather be detected during parsing?
For example, theastmodule does not give an AST at all for this:>> import ast; ast.parse("max(i for i in range(3),)") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.11/ast.py", line 50, in parse return compile(source, filename, mode, flags, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<unknown>", line 1 max(i for i in range(3),) ^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
Originally posted by @abhijeetbodas2001 in #17412
This is closely related to #12445, which handled the multiple-argument case, but CPython also raises an error for a single argument.
Reactions are currently unavailable