Repository navigation
Allow unary plus in match patterns on Python 3.15 - #28231
Merged
Merged
Conversation
Memory usage reportMemory usage unchanged ✅ |
|
|
Summary -- As added in python/cpython#148566, CPython now allows unary plus in match patterns, mirroring the support for unary minus. We already had a special case for this for improved error reporting and recovery, so I just swapped out the `add_error` call for `add_unsupported_syntax_error` with a new error kind. Test Plan -- New inline parser tests
ntBre
added a commit
that referenced
this pull request
Sep 1, 2026
Summary -- While reviewing #28231, Codex found a preexisting bug shared with our unary minus handling. Namely, CPython emits an error for code like this, where the unary expression is part of a longer expression: ```pycon >>> match foo: ... case -1**2: ... ... File "<python-input-0>", line 2 case -1**2: ... ^^ SyntaxError: invalid syntax ``` but Ruff does not: ```console $ ruff check --ignore ALL - <<EOF match foo: case -1**2: ... EOF All checks passed! ``` We now verify that the parsed unary expression is a number literal and emit an error if not. Test Plan -- New inline snapshots
ntBre
force-pushed
the
brent/315-match
branch
from
September 1, 2026 22:03
8995a33 to
133a7f6
Compare
ntBre
added a commit
that referenced
this pull request
Sep 1, 2026
Summary -- While reviewing #28231, Codex found a preexisting bug shared with our unary minus handling. Namely, CPython emits an error for code like this, where the unary expression is part of a longer expression: ```pycon >>> match foo: ... case -1**2: ... ... File "<python-input-0>", line 2 case -1**2: ... ^^ SyntaxError: invalid syntax ``` but Ruff does not: ```console $ ruff check --ignore ALL - <<EOF match foo: case -1**2: ... EOF All checks passed! ``` We now verify that the parsed unary expression is a number literal and emit an error if not. Test Plan -- New inline snapshots
ntBre
marked this pull request as ready for review
September 1, 2026 22:34
charliermarsh
approved these changes
Sep 2, 2026
ntBre
added a commit
that referenced
this pull request
Sep 2, 2026
Summary -- While reviewing #28231, Codex found a preexisting bug shared with our unary minus handling. Namely, CPython emits an error for code like this, where the unary expression is part of a longer expression: ```pycon >>> match foo: ... case -1**2: ... ... File "<python-input-0>", line 2 case -1**2: ... ^^ SyntaxError: invalid syntax ``` but Ruff does not: ```console $ ruff check --ignore ALL - <<EOF match foo: case -1**2: ... EOF All checks passed! ``` We now verify that the parsed unary expression is a number literal and emit an error if not. Test Plan -- New inline snapshots
ntBre
added a commit
that referenced
this pull request
Sep 2, 2026
Summary -- While reviewing #28231, Codex found a preexisting bug shared with our unary minus handling. Namely, CPython emits an error for code like this, where the unary expression is part of a longer expression: ```pycon >>> match foo: ... case -1**2: ... ... File "<python-input-0>", line 2 case -1**2: ... ^^ SyntaxError: invalid syntax ``` but Ruff does not: ```console $ ruff check --ignore ALL - <<EOF match foo: case -1**2: ... EOF All checks passed! ``` We now verify that the parsed unary expression is a number literal and emit an error if not. Test Plan -- New inline snapshots
1 task
1 task
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.
Summary
As added in python/cpython#148566, CPython now allows unary plus in match
patterns, mirroring the support for unary minus. We already had a special case for this for improved
error reporting and recovery, so I just swapped out the
add_errorcall foradd_unsupported_syntax_errorwith a new error kind.Part of #28206
Test Plan
New inline parser tests