gh-153171: Produce specialized syntax errors in more cases#153193
Closed
serhiy-storchaka wants to merge 1 commit into
Closed
gh-153171: Produce specialized syntax errors in more cases#153193serhiy-storchaka wants to merge 1 commit into
serhiy-storchaka wants to merge 1 commit into
Conversation
Report "'not' after an operator must be parenthesized" also for
'not' after shift, bitwise, comparison and power operators (each
operator tier gets its own error rule; a single rule matching bare
'not' at the operand position would misfire when a valid leading
'not' expression is followed by garbage).
Report "expected default value expression" also for a missing
parameter default value before ':' in lambda expressions and for
a missing type parameter default value (previously the latter
reported a misleading "expected '('").
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuation of gh-153171: a coverage audit of the error rules found more cases where a specialized error message is not produced in all positions where the invalid construct can occur.
'not' after an operator must be parenthesizedwas only reported after arithmetic and unary operators. Now it is also reported after shift, bitwise, comparison and power operators (1 << not x,1 & not x,1 < not x,2 ** not x). Each operator tier gets its own error rule requiring the actual preceding operator -- a single rule matching barenotat the operand position would misfire when a valid leadingnotexpression is followed by garbage (the "no misleading errors" cases in test_syntax guard exactly this).expected default value expressionwas not reported for a missing parameter default before:in lambda expressions (lambda x=: 0reported generic "invalid syntax").def f[T=](): pass,type X[T=] = int) reported a misleadingexpected '('. It could not be handled ininvalid_type_parambecause the base rule succeeds without consuming=(the default is optional), so it is handled at the type parameter list level.The remaining known gap (no specialized error for a starred expression at an operand position, e.g.
x = 1 + *y) is left out: an error alternative at the operand rule preempts better specialized errors in the second pass (e.g.X[**A: str]is explored as a subscript with a slice, anddel (*x,)loses "cannot delete starred"), so it needs a different approach.🤖 Generated with Claude Code