Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information