Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.2k
gh-145239: Specialize match syntax error for unary addition in pattern#145658
Open
mvanhorn wants to merge 1 commit intopython:mainfrom
Open
gh-145239: Specialize match syntax error for unary addition in pattern#145658mvanhorn wants to merge 1 commit intopython:mainfrom
mvanhorn wants to merge 1 commit intopython:mainfrom
Conversation
…patternAdd a specialized syntax error message when unary '+' is used in matchpatterns. Instead of the generic "invalid syntax", users now see:"cannot use unary '+' in a literal pattern".This applies to all pattern contexts: top-level, alternatives, sequences,class patterns, and mapping patterns.Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
python-cla-botbot commentedMar 9, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Contributor
Shrey-N commentedMar 9, 2026 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Also@mvanhorn, Just a heads up, if you accept the |
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 freeto 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.
Uh oh!
There was an error while loading.Please reload this page.
Fixes#145239.
Adds a specialized syntax error message when unary
+is used in match patterns. Instead of the generic "invalid syntax", users now see a clear message:"cannot use unary '+' in a literal pattern".This applies to all pattern contexts: top-level, alternatives, sequences, class patterns, and mapping patterns.
Changes
Grammar/python.gram: Addedinvalid_literal_patternrule that catches'+' NUMBERand raises the specialized errorParser/parser.c: Regenerated from grammarLib/test/test_syntax.py: Added doctest-style tests for all pattern contextsLib/test/test_patma.py: Added unit tests inTestSyntaxErrorsMisc/NEWS.d: Added NEWS entryExample
Before:
After:
This contribution was developed with AI assistance (Claude Code).
matchsyntax error for unary addition in pattern #145239