ruff/crates/ruff_python_parser/src/parser
Brent Westbrook 318f503714
[syntax-errors] Named expressions in decorators before Python 3.9 (#16386)
Summary
--

This PR detects the relaxed grammar for decorators proposed in [PEP
614](https://peps.python.org/pep-0614/) on Python 3.8 and lower.

The 3.8 grammar for decorators is
[here](https://docs.python.org/3.8/reference/compound_stmts.html#grammar-token-decorators):

```
decorators                ::=  decorator+
decorator                 ::=  "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE
dotted_name               ::=  identifier ("." identifier)*
```

in contrast to the current grammar
[here](https://docs.python.org/3/reference/compound_stmts.html#grammar-token-python-grammar-decorators)

```
decorators                ::= decorator+
decorator                 ::= "@" assignment_expression NEWLINE
assignment_expression ::= [identifier ":="] expression
```

Test Plan
--

New inline parser tests.
2025-03-05 17:08:18 +00:00
..
snapshots Update insta snapshots (#14366) 2024-11-15 19:31:15 +01:00
expression.rs [syntax-errors] Named expressions in decorators before Python 3.9 (#16386) 2025-03-05 17:08:18 +00:00
helpers.rs [syntax-errors] Named expressions in decorators before Python 3.9 (#16386) 2025-03-05 17:08:18 +00:00
mod.rs [syntax-errors] except* before Python 3.11 (#16446) 2025-03-02 18:20:18 +00:00
options.rs Start detecting version-related syntax errors in the parser (#16090) 2025-02-25 23:03:48 -05:00
pattern.rs Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00
progress.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
recovery.rs Use CompactString for Identifier (#12101) 2024-07-01 10:06:02 +02:00
statement.rs [syntax-errors] Named expressions in decorators before Python 3.9 (#16386) 2025-03-05 17:08:18 +00:00
tests.rs Pass ParserOptions to the parser (#16220) 2025-02-19 10:50:50 -05:00