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 — `int.__round__(None)` is not supported · Issue #120080 · python/cpython

int.__round__(None) is not supported #120080

New issue
Copy link
New issue
Copy link
Closed
Closed
int.__round__(None) is not supported#120080
Copy link
Labels
3.14bugs and security fixesbugs and security fixeseasytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@JelleZijlstra
JelleZijlstra
opened on Jun 4, 2024
Issue body actions

Bug report

Bug description:

The __round__ method on floats accepts None as an explicit argument, but the one on int does not:

>>> (1.0).__round__(None)
1
>>> (1).__round__(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object cannot be interpreted as an integer

This goes against the general principle that any operation that works on a float should also work on an int.

(Note that both round(x) and round(x, None) work on both floats and ints; this issue is entirely about direct calls to .__round__().)

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-120080: Accept None as a valid argument for direct call of the int.__round__ #120088
  • [3.13] gh-120080: Accept None as a valid argument for direct call of the int.__round__ (GH-120088) #120197
  • gh-120080: Mark test_round_with_none_arg_direct_call as cpython_only #120328

Activity

  1. JelleZijlstra
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    easy
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    3.14bugs and security fixesbugs and security fixes
    and removed
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    on Jun 4, 2024
  2. serhiy-storchaka commented on Jun 5, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 5, 2024
    Member
    More actions

    I do not think that there is a bug. The operation that works on a float and on an int is round(x, None), the rest is an implementation detail. You do not expect that int.__add__ works on a float, aren't?

    Reacted by Gouvernathor
  3. vstinner
    added a commit that references this issue on Jun 7, 2024

    gh-120080: Accept ``None`` as a valid argument for direct call of the…

    57ad769
  4. miss-islington
    added a commit that references this issue on Jun 7, 2024

    pythongh-120080: Accept ``None`` as a valid argument for direct call …

    4e3866e
  5. vstinner commented on Jun 7, 2024

    @vstinner
    vstinner
    on Jun 7, 2024
    Member
    More actions

    Fixed by commit: 57ad769. See my rationale for the change: #120088 (comment).

  6. vstinner
    closed this as completedon Jun 7, 2024
  7. serhiy-storchaka commented on Jun 7, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 7, 2024
    Member
    More actions

    Note that Decimal.__round__ does not accept None. And perhaps many third-party numeric types do not accept it. Implementing this for int.__round__ sends a false signal that this is required. It won't be long before somebody open an issue about Decimal.__round__, and then authors of third-party libraries will be under pressure to implement this unneeded feature in their code. This opened a can of worms, and we do not know what long term consequences will be.

    Not everything that can be implemented should be implemented, and I believe that this is such a case.

    Reacted by Erlend E. Aasland and Gouvernathor
  8. vstinner commented on Jun 7, 2024

    @vstinner
    vstinner
    on Jun 7, 2024
    Member
    More actions

    My motivation to merge the PR was to avoid <unrepresentable> in the function signature. This marker causes issues. See for example: https://discuss.python.org/t/ac-null-defaults-prevent-correct-signatures-lets-add-inspect-unrepresentable-to-fix-this/30753

  9. serhiy-storchaka commented on Jun 7, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 7, 2024
    Member
    More actions

    #73536 is the general solution of this problem.

    Reacted by Erlend E. Aasland
  10. vstinner commented on Jun 7, 2024

    @vstinner
    vstinner
    on Jun 7, 2024
    Member
    More actions

    #73536 is the general solution of this problem.

    Ok, but this issue is open since 2017 and is not fixed yet.

    IMO accepting None is just a harmless way to fix the issue.

  11. serhiy-storchaka commented on Jun 7, 2024

    @serhiy-storchaka
    serhiy-storchaka
    on Jun 7, 2024
    Member
    More actions

    Few months ago I finally created a draft (#117671). I hope this will be included in 3.14.

    Reacted by Erlend E. Aasland and Victor Stinner
  12. Eclips4
    added a commit that references this issue on Jun 10, 2024

    pythongh-120080: Mark test as cpython_only

    769aae4
  13. vstinner
    added a commit that references this issue on Jun 11, 2024

    gh-120080: Mark test_round_with_none_arg_direct_call as cpython_only (#…

    02c1dff
  14. mrahtz
    added a commit that references this issue on Jun 30, 2024

    pythongh-120080: Mark test_round_with_none_arg_direct_call as cpython…

    22ffaf4
  15. estyxx
    added 2 commits that reference this issue on Jul 17, 2024

    pythongh-120080: Accept ``None`` as a valid argument for direct call …

    86ce3ff

    pythongh-120080: Mark test_round_with_none_arg_direct_call as cpython…

    b973063
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixesbugs and security fixeseasytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    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.