Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-145239: Specialize match syntax error for unary addition in pattern#145658

Open
mvanhorn wants to merge 1 commit intopython:mainfrom
mvanhorn:osc/145239-match-unary-add-syntax-error
Open

gh-145239: Specialize match syntax error for unary addition in pattern#145658
mvanhorn wants to merge 1 commit intopython:mainfrom
mvanhorn:osc/145239-match-unary-add-syntax-error

Conversation

@mvanhorn
Copy link

@mvanhornmvanhorn commentedMar 9, 2026
edited by bedevere-appbot
Loading

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_pattern rule that catches'+' NUMBER and raises the specialized error
  • Parser/parser.c: Regenerated from grammar
  • Lib/test/test_syntax.py: Added doctest-style tests for all pattern contexts
  • Lib/test/test_patma.py: Added unit tests inTestSyntaxErrors
  • Misc/NEWS.d: Added NEWS entry

Example

matchsubject:case+1:pass

Before:

SyntaxError: invalid syntax

After:

SyntaxError: cannot use unary '+' in a literal pattern

This contribution was developed with AI assistance (Claude Code).

…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-bot
Copy link

python-cla-botbot commentedMar 9, 2026
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

@Shrey-N
Copy link
Contributor

Shrey-N commentedMar 9, 2026
edited
Loading

Also@mvanhorn, Just a heads up, if you accept thepython.gram suggestions via the GitHub UI, remember to pull locally and regenerateParser/parser.c before your next push, otherwise the CI will fail. :)

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@brandtbucherbrandtbucherAwaiting requested review from brandtbucherbrandtbucher is a code owner

@pablogsalpablogsalAwaiting requested review from pablogsalpablogsal is a code owner

@lysnikolaoulysnikolaouAwaiting requested review from lysnikolaoulysnikolaou is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Specializematch syntax error for unary addition in pattern

2 participants

@mvanhorn@Shrey-N

[8]ページ先頭

©2009-2026 Movatter.jp