-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit 4b7b98c
committed
Detect named expressions in decorators before Python 3.9
Summary
--
This PR detects another syntax error from #6591 and is stacked on #16383. This
time the relaxed grammar for decorators proposed in [PEP
614](https://peps.python.org/pep-0614/) is detected for 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
```
This was the trickiest one of these to detect yet. It seemed like the best
approach was to attempt to parse the old version and fall back on the new
grammar if anything goes wrong, but I'm not as confident in this approach since
it required adding a `Parser::try_parse_old_decorators` method.
Test Plan
--
New inline parser tests and linter CLI tests.1 parent 6386a86 commit 4b7b98cCopy full SHA for 4b7b98c
File tree
0 file changed
+0
-0
lines changedFilter options
0 file changed
+0
-0
lines changed
0 commit comments