Skip to content

int.__round__(None) is not supported #120080

Closed
@JelleZijlstra

Description

@JelleZijlstra

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions