GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Consider having int() support MINUS SIGN · Issue #144087 · python/cpython

Consider having int() support MINUS SIGN #144087

New issue
Copy link
New issue
Copy link
Open
Open
Consider having int() support MINUS SIGN#144087
Copy link
Assignees
johnslavik
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Description

@rhettinger
rhettinger
opened on Jan 20, 2026
Issue body actions

The int() function supports all Nd unicode digit variants so that int('\N{digit one}') == int('\N{arabic-indic digit one}').

Likewise, the int() function supports all Zs space character variants to that int('\N{space}123') == int('\N{no-break space}123').

However, the function does not support negation variants so that int('\N{hyphen-minus}\N{digit one}') succeeds while int('\N{minus sign}\N{digit one}') fails.

I found this issue while parsing a Table of Jacobi Symbol Values. All of the −1 entries are a MINUS SIGN and DIGIT ONE. I would have expected all minus sign variants to be supported.

Linked PRs

  • gh-144087: Add support for unicode MINUS SIGN in int, float and complex #144095
Reacted by Martin Panter, Bartosz Sławecki, Łukasz Langa and Jason R. Coombs

Activity

Next
  1. johnslavik
    added
    type-featureA feature request or enhancementA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    and removed
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    on Jan 21, 2026
  2. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    If we normalize MINUS SIGN to HYPHEN-MINUS in _PyUnicode_TransformDecimalAndSpaceToASCII, that will also affect float and complex. I think this is the correct and desired approach.

    We can consider updating _pylong.str_to_int, but it is not used by us and maybe that one would need a more general rework (rather than just changing one specific thing to increase parity) according to this comment:

    cpython/Lib/_pylong.py

    Lines 402 to 404 in 8951088

    def str_to_int(s):
    """Asymptotically fast version of decimal string to 'int' conversion."""
    # FIXME: this doesn't support the full syntax that int() supports.

    We don't use this one internally. We instead sometimes use _pylong.int_from_string that has sign conversion already covered by _PyUnicode_TransformDecimalAndSpaceToASCII when called.

    I believe _PyUnicode_TransformDecimalAndSpaceToASCII to be the right place to handle this.

  3. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    Prior discussion: #54790 (comment)

  4. skirpichev commented on Jan 21, 2026

    @skirpichev
    skirpichev
    on Jan 21, 2026
    Member
    More actions

    the function does not support negation variants so that int('\N{hyphen-minus}\N{digit one}') succeeds while int('\N{minus sign}\N{digit one}') fails.

    Indeed, this looks odd. The \N{plus sign} is supported.

    all minus sign variants

    Could you be more precise here, do we need something else?

    I imagine, that many dash-like characters might erroneously be used for minus sign. E.g.:

    >>> s = '\u2011\N{digit one}'; print(s)
    ‑1
    >>> -1  # find the difference? :-)
    -1
    >>> int(s)
    Traceback (most recent call last):
      File "<python-input-6>", line 1, in <module>
        int(s)
        ~~~^^^
    ValueError: invalid literal for int() with base 10: '‑1'
  5. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    @skirpichev yes, but MINUS SIGN is specifically supposed to be used as the mathematical minus. That's why it ended up on Wikipedia.

    IMO, MINUS SIGN is the right additional case to support, and anything else that looks similar is okay to be unsupported. We could revisit any additional cases if someone asks for it, but my gut instinct is that it's very unlikely.

    Reacted by Sergey B Kirpichev, Łukasz Langa and Jason R. Coombs
  6. skirpichev commented on Jan 21, 2026

    @skirpichev
    skirpichev
    on Jan 21, 2026
    Member
    More actions

    If we normalize MINUS SIGN to HYPHEN-MINUS in _PyUnicode_TransformDecimalAndSpaceToASCII, that will also affect float and complex.

    That's ok, as they all support unicode digits.

    But not forget about Decimal's, which don't use this helper.

    Reacted by Bartosz Sławecki
  7. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    But not forget about Decimal's, which don't use this helper.

    Good note. For the decimal type, we'd update numeric_as_ascii.

    Fractions don't support MINUS SIGN as well:

    >>> fractions.Fraction("\N{MINUS SIGN}1")
    Traceback (most recent call last):
      ...
    ValueError: Invalid literal for Fraction: '−1'
    >>> fractions.Fraction("-1")
    Fraction(-1, 1)

    for these we'd update fractions._RATIONAL_FORMAT.

  8. skirpichev commented on Jan 21, 2026

    @skirpichev
    skirpichev
    on Jan 21, 2026
    Member
    More actions

    Fractions don't support this as well

    Yeah. You will need to change fractions module just like _pydecimal.

    Reacted by Bartosz Sławecki
  9. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    FWIW, wcstol doesn't seem to support this.

    However, given prior discussions years ago, I think this is still a good idea, esp. for parsing documents that contain numbers with this sign.
    To me, this is similar in nature to handling the final form of capital sigma Σ in str.lower().

  10. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    This feature was requested by @ambv in 2013: https://mail.python.org/pipermail/python-ideas/2013-June/021217.html.
    See also https://mail.python.org/pipermail/python-ideas/2013-June/021243.html.

    The last message in the thread concluded on support for this feature request: https://mail.python.org/pipermail/python-ideas/2013-June/021273.html.

    Łukasz, what was the reception of this proposal at the time? Do you know if the proposal was suddenly declined or deferred at some point, or maybe just not revisited later? What do you think about it today?

  11. johnslavik commented on Jan 21, 2026

    @johnslavik
    johnslavik
    on Jan 21, 2026
    Member
    More actions

    CC @sethmlarson as security expert

  12. rhettinger commented on Jan 21, 2026

    @rhettinger
    rhettinger
    on Jan 21, 2026
    ContributorAuthor
    More actions

    all minus sign variants

    Could you be more precise here, do we need something else?

    MINUS SIGN and HYPHEN-MINUS are the only ones I know of.

    Reacted by Łukasz Langa
  13. 8 remaining items

  14. encukou commented on Mar 3, 2026

    @encukou
    encukou
    on Mar 3, 2026
    Member
    More actions

    The non-ASCII decimal digits have some backing in Unicode -- there are official categories for decimal digits, and their values. [1]

    But there's no such thing for signs like minus. We're essentially doing the job of the Unicode consortium -- deciding on character properties. Doing that correctly is hard. I don't know how to do it correctly, but I know we're all out of our depth here.

    Adding a character after of seeing it used in a table is a bad precedent; it leaves us with unbounded scope for similar requests in the future. That's not a good thing to maintain.

    Do you have some specific idea?

    The default is to keep the status quo. Accepting only - and + is fine.


    [1] I'd argue that we're not using them correctly though -- int('१২௩4') is just nonsense. That's water under the bridge, but let's not spill it further.

  15. randolf-scholz commented on Mar 3, 2026

    @randolf-scholz
    randolf-scholz
    on Mar 3, 2026
    Contributor
    More actions

    But there's no such thing for signs like minus.

    There are decompositions:

    >>> import unicodedata
    >>> unicodedata.name("\uff0d")
    'FULLWIDTH HYPHEN-MINUS'
    >>> unicodedata.decomposition("\uff0d")
    '<wide> 002D'

    However, U+2212 (MINUS SIGN) does not decompose.

  16. encukou commented on Mar 9, 2026

    @encukou
    encukou
    on Mar 9, 2026
    Member
    More actions

    Should we honour decompositions?
    int('²') and float('3ₑ2') currently raise, though these strings decompose to 2 and 3e2.

  17. skirpichev commented on Mar 10, 2026

    @skirpichev
    skirpichev
    on Mar 10, 2026
    Member
    More actions

    there are official categories for decimal digits, and their values.

    Sign characters is a too narrow area to deserve a separate category.

    But there's no such thing for signs like minus.

    IMO, character name (\N{minus sign}) and its category (Math symbol, mathematical operators) speaks for itself.

    int('²') and float('3ₑ2') currently raise

    I think it's correct. '²' is a superscript character, 'ₑ' - subscript. This is for powers, array indexes and so on.

  18. johnslavik commented on Mar 12, 2026

    @johnslavik
    johnslavik
    on Mar 12, 2026
    Member
    More actions

    This feature was requested and accepted long ago. I think we can add support for more signs over time as needed.

  19. johnslavik commented on Apr 1, 2026

    @johnslavik
    johnslavik
    on Apr 1, 2026
    Member
    More actions

    The int() function supports all Nd unicode digit variants (...).
    Likewise, the int() function supports all Zs space character variants (...).
    However, the function does not support negation variants (...)

    @rhettinger, is parity with existing support for Unicode characters the only rationale for this proposal? Does it aim to fully solve a bigger, well-defined problem, or is it a mere convenience? cc @ambv

    I'm considering whether keeping the status quo with an easy str.replace always at hand isn't more desirable. Are there any cases you have (or had) in mind where having Unicode minus sign support in the int constructor (and, with the current state of things, in float and complex constructors as well) would be an undeniable win?

    Personally, parity was the only argument that initially bought me, but now I'm having second thoughts. I'm looking at https://peps.python.org/pep-0672/#confusable-digits and I'm thinking: oh no, this is some shady business.

    Reacted by Petr Viktorin
  20. johnslavik commented on Apr 1, 2026

    @johnslavik
    johnslavik
    on Apr 1, 2026
    Member
    More actions

    I'd zero in on MINUS SIGN, in parity with the ASCII PLUS SIGN that is already supported.

    I've used this argument but it doesn't work if we look at it within Python. All Python operators are ASCII, and that means the ASCII hyphen minus is more relevant than the Unicode minus sign when collating with ASCII plus sign.

  21. johnslavik
    pinned and unpinned a comment on Apr 1, 2026
  22. skirpichev commented on Apr 1, 2026

    @skirpichev
    skirpichev
    on Apr 1, 2026
    Member
    More actions

    I'm looking at https://peps.python.org/pep-0672/#confusable-digits and I'm thinking: oh no, this is some shady business.

    What you find confusing in the minus sign?

    All Python operators are ASCII

    Current proposal doesn't touch operators. It's not about of the language syntax, but about string parsing. To make it useful, we must accept more permissive syntaxes. Convenience is an argument here. If unicode character is used on practice as an alternative to ASCII minus - why reject it?

    Supporting arbitrary unicode digits was rather an unfortunate precedent, as it now allows to mix them in a meaningless way, e.g. eastern and western arabic digits in one number. But it's already there...

    Reacted by Petr Viktorin
  23. encukou commented on Apr 2, 2026

    @encukou
    encukou
    on Apr 2, 2026
    Member
    More actions

    I'm considering whether keeping the status quo with an easy str.replace always at hand more desirable.

    IMO, for the Unicode minus sign, it is.
    As a first step toward adding more other characters, this is an issue with extremely large potential scope. Before opening the can of worms, we should have an idea of how far down the rabbit hole we're willing to go, and which dead ends we avoid.

    “ASCII-only” is a good line to draw.

    Reacted by Bartosz Sławecki
  24. skirpichev
    self-assigned this
    on Jul 21, 2026
  25. skirpichev commented on Jul 21, 2026

    @skirpichev
    skirpichev
    on Jul 21, 2026
    Member
    More actions

    “ASCII-only” is a good line to draw.

    The problem is that line was already crossed. E.g. from the issue description:

    The int() function supports all Nd unicode digit variants so that int('\N{digit one}') == int('\N{arabic-indic digit one}').

    I think that a strong point in favor is that it mirrors the unicode plus sign (\N{plus sign}), which is already supported. That was already noticed in previous discussions: https://mail.python.org/pipermail/python-ideas/2013-June/021273.html

    But that is from purity arguments. Strongest one is from practice:

    I found this issue while parsing a Table of Jacobi Symbol Values. All of the −1 entries are a MINUS SIGN and DIGIT ONE.

  26. johnslavik commented on Jul 21, 2026

    @johnslavik
    johnslavik
    on Jul 21, 2026
    Member
    More actions

    cc @savannahostrowski (I briefly mentioned this to you at sprints)

  27. skirpichev
    removed their assignment
    on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @johnslavik
    johnslavik

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.