Skip to content

gh-153171: Produce specialized syntax errors for 'not' after an operator in more positions#153175

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:error-rules-placement
Jul 6, 2026
Merged

gh-153171: Produce specialized syntax errors for 'not' after an operator in more positions#153175
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:error-rules-placement

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jul 6, 2026

Copy link
Copy Markdown
Member

Move the invalid_factor error rule from term to factor and the invalid_arithmetic error rule from shift_expr to sum, so that they are tried at all positions where the invalid construct can occur, not only where the rule which previously contained them starts.

Previously a generic error was reported when the construct occurred at a deeper position:

>>> 1 * + not x
SyntaxError: invalid syntax
>>> 2 ** + not x
SyntaxError: invalid syntax
>>> 1 << 2 + not x
SyntaxError: invalid syntax

Now all of them report SyntaxError: 'not' after an operator must be parenthesized.

All previously produced error messages are unchanged: this only produces specialized errors where a generic error was reported before.

🤖 Generated with Claude Code

… operator in more positions

Move the invalid_factor rule from term to factor and the
invalid_arithmetic rule from shift_expr to sum, so that they are
tried at all positions where the invalid construct can occur.
Previously a generic "invalid syntax" error was reported for
constructs like "1 << 2 + not x" or "1 * + not x".

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@pablogsal

Copy link
Copy Markdown
Member

LGTM

@serhiy-storchaka serhiy-storchaka merged commit 1034e73 into python:main Jul 6, 2026
104 of 106 checks passed
@serhiy-storchaka serhiy-storchaka deleted the error-rules-placement branch July 6, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants