Skip to content

gh-120080: Accept None as a valid argument for direct call of the int.__round__ #120088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 7, 2024

Conversation

Eclips4
Copy link
Member

@Eclips4 Eclips4 commented Jun 5, 2024

@Eclips4 Eclips4 requested a review from JelleZijlstra June 5, 2024 05:50
@Eclips4 Eclips4 added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Jun 5, 2024
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

:)

Co-authored-by: Nikita Sobolev <[email protected]>
@Eclips4
Copy link
Member Author

Eclips4 commented Jun 5, 2024

Thanks for the review, Nikita!

@vstinner vstinner merged commit 57ad769 into python:main Jun 7, 2024
38 checks passed
@miss-islington-app
Copy link

Thanks @Eclips4 for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 7, 2024
…of the ``int.__round__`` (pythonGH-120088)

(cherry picked from commit 57ad769)

Co-authored-by: Kirill Podoprigora <[email protected]>
Co-authored-by: Nikita Sobolev <[email protected]>
@miss-islington-app
Copy link

Sorry, @Eclips4 and @vstinner, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 57ad769076201c858a768d81047f6ea44925a33b 3.12

@bedevere-app
Copy link

bedevere-app bot commented Jun 7, 2024

GH-120197 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jun 7, 2024
@vstinner vstinner removed the needs backport to 3.12 only security fixes label Jun 7, 2024
@vstinner
Copy link
Member

vstinner commented Jun 7, 2024

I merged the change. Thanks @Eclips4!

I don't think that such change deserves to be backported. It's a minor issue.

While @serhiy-storchaka disagrees with the change: #120080 (comment), IMO it makes the code more consistent. With this change, round(), float.__round__() and int.__round__() accept None for ndigits. It also makes help(nt.__round__) nicer. If tomorrow, we decide to reject None, it should be consistent and be rejected in the 3 ways to call "round". But I don't think that we want to reject None, it's convenient and works currently.

Note: I would prefer to have 0 as the default value rather than None. But well, it's too change to change such detail :-)

Internally, round(obj, None) calls obj.__round__() (0 arguments), whereas round(obj, ndigits) calls obj.__round__(ndigits) (1 argument).

@Eclips4 Eclips4 deleted the issue-120080 branch June 7, 2024 08:14
@serhiy-storchaka
Copy link
Member

float.__round__() needs to distinguish 0 from no argument. Accepting None is just an implementation detail. I do not think we should add tests for this, because now this becomes a self-official feature.

int.__round__() could have 0 as the default, this would simplify the code.

@vstinner
Copy link
Member

vstinner commented Jun 7, 2024

I do not think we should add tests for this, because now this becomes a self-official feature.

The tests can be decorated with @support.cpython_only.

noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
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.

4 participants