Uh oh!
There was an error while loading. Please reload this page.
gh-145239: Accept unary plus literal pattern - #148566
Conversation
Add '+' alternatives to signed_number and signed_real_number grammar rules, mirroring how unary minus is already handled. Unary plus is a no-op on numbers so the value is returned directly without wrapping in a UnaryOp node.
Mirror the existing negative-number tests (095-110) for positive numbers: integers, floats, imaginary, and complex patterns.
Assuming astral-sh/ruff#16394 (comment) is still correct, there's no other way around
sunmy2019
commented
Apr 14, 2026
You may also want to update this doc. |
Fun fact is that technically |
Uh oh!
There was an error while loading. Please reload this page.
Eclips4
left a comment
There was a problem hiding this comment.
LGTM. This makes pattern matching more consistent.
Will merge tomorrow if no one has anything to say.
Uh oh!
There was an error while loading. Please reload this page.
Add '+' alternatives to signed_number and signed_real_number grammar rules, mirroring how unary minus is already handled for pattern matching. Unary plus is a no-op on numbers so the value is returned directly without wrapping in a UnaryOp node.
| imaginary_number[expr_ty]: | ||
| | imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) } | ||
| | '+' imag=NUMBER { _PyPegen_ensure_imaginary(p, imag) } |
There was a problem hiding this comment.
Since imaginary_number is always preceded by + or - already, this makes the following pass:
match1:
case1++1j:
pass@johnslavik, do you want to fix this? Removing this case should do it.
There was a problem hiding this comment.
Yes; I'll be back home from a trip soon and I'll fix it.
There was a problem hiding this comment.
@encukou Let's revisit this at EuroPython sprints.
There was a problem hiding this comment.
I tend to be pretty busy at sprints; could you ask here?
LMK if you'd like the tests shortened. I copy-pasted the existing cases, but I'm tempted to shorten it drastically. You decide!
For example, I don't see the point in
self.assertEqualonx.matchsyntax error for unary addition in pattern #145239