From c41e329bc40cf31cd650a321b0361879b97a1917 Mon Sep 17 00:00:00 2001 From: Brent Westbrook Date: Tue, 25 Feb 2025 17:42:00 -0500 Subject: [PATCH] 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.