Skip to content

gh-154775: Don't accept duplicate plus sign when matching complex number - #154776

Merged
encukou merged 3 commits into
python:mainfrom
encukou:no-extra-plus
Jul 28, 2026
Merged

gh-154775: Don't accept duplicate plus sign when matching complex number#154776
encukou merged 3 commits into
python:mainfrom
encukou:no-extra-plus

Conversation

@encukou

@encukou encukou commented Jul 27, 2026

Copy link
Copy Markdown
Member

When matching a complex literal in :keyword:case statements, an extraneous
+ sign is no longer allowed (for example, in 1++1j or 1-+1j).

Comment thread Lib/test/test_patma.py
@johnslavik

johnslavik commented Jul 27, 2026

Copy link
Copy Markdown
Member

Oops, I tried to help but my GitHub suggestion didn't apply correctly. test_patma_265 is at fault.

@johnslavik

Copy link
Copy Markdown
Member

Thanks so much for fixing this!

@skirpichev

Copy link
Copy Markdown
Member

I would prefer to save ability to use +1j, as now. Probably you could do this, adding case like removed to the complex_number rule.

@encukou

encukou commented Jul 28, 2026

Copy link
Copy Markdown
Member Author

I would prefer to save ability to use +1j, as now.

You can still do this; in the diff you can see the new test_patma_265, which passes with case +1e1000:.

Probably you could do this, adding case like removed to the complex_number rule.

#148566 already did that ([edit] to signed_number & signed_real_number); that's why the double + was accepted. This only removes one of the two duplicates.


The test that @johnslavik removed is for case 0.25 - +1.75j:, which is as wrong as 0.25 ++ 1.75j.

@encukou
encukou merged commit a85830c into python:main Jul 28, 2026
53 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@encukou
encukou deleted the no-extra-plus branch July 28, 2026 07:19
@bedevere-app

bedevere-app Bot commented Jul 28, 2026

Copy link
Copy Markdown

GH-154802 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 28, 2026
encukou added a commit that referenced this pull request Jul 28, 2026
…lex number (GH-154776) (GH-154802)

(cherry picked from commit a85830c)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Bartosz Sławecki <bartosz@ilikepython.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants