Repository navigation
Validate unary expressions when parsing - #28233
Merged
Merged
Conversation
Memory usage reportMemory usage unchanged ✅ |
|
ntBre
force-pushed
the
brent/signed-literal-parsing
branch
from
September 1, 2026 22:03
d4f3c64 to
9cdbc1c
Compare
|
ntBre
force-pushed
the
brent/signed-literal-parsing
branch
from
September 1, 2026 22:33
9cdbc1c to
083ddcc
Compare
ntBre
marked this pull request as ready for review
September 1, 2026 22:34
charliermarsh
approved these changes
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
force-pushed
the
brent/signed-literal-parsing
branch
from
September 2, 2026 13:16
083ddcc to
7d77176
Compare
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
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:
but Ruff does not:
We now verify that the parsed unary expression is a number literal and emit an error if not.
Test Plan
New inline snapshots