Skip to content

gh-144087: Add support for unicode MINUS SIGN in int, float and complex - #144095

Closed
johnslavik wants to merge 31 commits into
python:mainfrom
johnslavik:feat-handle-minus-sign
Closed

gh-144087: Add support for unicode MINUS SIGN in int, float and complex#144095
johnslavik wants to merge 31 commits into
python:mainfrom
johnslavik:feat-handle-minus-sign

Conversation

@johnslavik

@johnslavikjohnslavik commented Jan 21, 2026

Copy link
Copy Markdown
Member

I don't see a different approach to solving this that is equally or more optimal in terms of trade-offs. If there's any alternative approach that I've missed, please let me know.

@jaraco

Copy link
Copy Markdown
Member

LGTM. Needs tests and blurb. Maybe consider making the assignment a constant instead of a comment, though I don't feel strongly about it.

@johnslavik

johnslavik commented Jan 24, 2026

Copy link
Copy Markdown
MemberAuthor

LGTM. Needs tests and blurb.

Yep! Work in progress.

Thanks for chiming in :)

@skirpichev

Copy link
Copy Markdown
Member

This also needs documentation. I would guess, it will take major part of the PR.

@picnixz

Copy link
Copy Markdown
Member

I don't see a different approach to solving this that is equally or more optimal in terms of trade-offs

How about only checking for the first non whitespace character? signs should not appear in the middle of a number unless they are in the e/E/p suffix I guess?

@skirpichev

Copy link
Copy Markdown
Member

How about only checking for the first non whitespace character?

Hardly this optimizes something.

unless they are in the e/E/p suffix I guess?

Yes. _PyUnicode_TransformDecimalAndSpaceToASCII() used for floats and complexes (which gives another case of "sign in the middle") too.

@johnslavik
johnslavik marked this pull request as ready for review February 21, 2026 10:46
@johnslavik

Copy link
Copy Markdown
MemberAuthor

This seems like something we could add to the "What's New" log. I'll do that.

@johnslavik

johnslavik commented Mar 2, 2026

Copy link
Copy Markdown
MemberAuthor

@picnixz, @skirpichev, I tagged you for reviews because I thought you may be interested now that it is ready :-)

I'm particularly unsure about whether I missed or added unnecessary tests, and whether the documentation changes are good.

Comment threadLib/test/test_int.py

@skirpichevskirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with minor nitpicks.

Maybe you can do docs more compact. See suggestions as an example.

Alternatively, omit just "(ASCII plus sign)" clarifications. There shouldn't be much confusion. Visual difference for '-' and '−' is less apparent.

Comment threadDoc/library/functions.rst Outdated
Comment threadDoc/library/functions.rst Outdated
Comment threadDoc/library/functions.rst Outdated
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Comment threadDoc/library/functions.rst Outdated
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>

@skirpichevskirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note also, that we have a separate parsing from string code in the fromhex() class method.

I don't see good reasons to reject new sign character here, if we are going to support in the float constructor.

Comment threadDoc/library/functions.rst Outdated
Comment threadDoc/library/functions.rst
Comment threadDoc/library/functions.rst Outdated
Comment threadDoc/library/stdtypes.rst Outdated
Comment threadDoc/library/functions.rst Outdated
def test_float(self):
self.assertEqual(float(3.14), 3.14)
self.assertEqual(float(314), 314.0)
self.assertEqual(float(" 3.14 "), 3.14)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can add here also tests for parsing floats in scientific notation, with exponent.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I'll address this on the weekend.

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@johnslavik

Copy link
Copy Markdown
MemberAuthor

Please do not merge this. I need to collect more feedback on the idea.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsBot added the stale Stale PR or inactive for long period of time. label May 5, 2026
@johnslavik

Copy link
Copy Markdown
MemberAuthor

I'm not sure it is worth it. Feel free to pick this up if you want!

@johnslavik
johnslavik deleted the feat-handle-minus-sign branch July 21, 2026 01:55
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core reviewDO-NOT-MERGEstaleStale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@johnslavik@jaraco@skirpichev@picnixz@encukou@ambv