ruff/crates/ruff_python_parser/src
Dhruv Manilawala 978909fcf4
Raise syntax error for unparenthesized generator expr in multi-argument call (#12445)
## Summary

This PR fixes a bug to raise a syntax error when an unparenthesized
generator expression is used as an argument to a call when there are
more than one argument.

For reference, the grammar is:
```
primary:
    | ...
    | primary genexp 
    | primary '(' [arguments] ')' 
    | ...

genexp:
    | '(' ( assignment_expression | expression !':=') for_if_clauses ')' 
```

The `genexp` requires the parenthesis as mentioned in the grammar. So,
the grammar for a call expression is either a name followed by a
generator expression or a name followed by a list of argument. In the
former case, the parenthesis are excluded because the generator
expression provides them while in the later case, the parenthesis are
explicitly provided for a list of arguments which means that the
generator expression requires it's own parenthesis.

This was discovered in https://github.com/astral-sh/ruff/issues/12420.

## Test Plan

Add test cases for valid and invalid syntax.

Make sure that the parser from CPython also raises this at the parsing
step:
```console
$ python3.13 -m ast parser/_.py
  File "parser/_.py", line 1
    total(1, 2, x for x in range(5), 6)
                ^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized

$ python3.13 -m ast parser/_.py
  File "parser/_.py", line 1
    sum(x for x in range(10), 10)
        ^^^^^^^^^^^^^^^^^^^^
SyntaxError: Generator expression must be parenthesized
```
2024-07-22 14:44:20 +05:30
..
lexer Mention that Cursor is based on rustc's implementation. (#12109) 2024-06-30 16:53:25 +01:00
parser Raise syntax error for unparenthesized generator expr in multi-argument call (#12445) 2024-07-22 14:44:20 +05:30
snapshots Use CompactString for Identifier (#12101) 2024-07-01 10:06:02 +02:00
error.rs Raise syntax error for unparenthesized generator expr in multi-argument call (#12445) 2024-07-22 14:44:20 +05:30
lexer.rs Use CompactString for Identifier (#12101) 2024-07-01 10:06:02 +02:00
lib.rs Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
string.rs Move token and error structs into related modules (#11957) 2024-06-21 10:07:19 +00:00
token.rs Use CompactString for Identifier (#12101) 2024-07-01 10:06:02 +02:00
token_set.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
token_source.rs Use TokenSource to find new location for re-lexing (#12060) 2024-06-27 17:12:39 +05:30
typing.rs Update type annotation parsing API to return Parsed (#11739) 2024-06-05 12:59:43 +05:30