GeezerVison is showing github.com — gh-120080: Accept ``None`` as a valid argument for direct call of the ``int.__round__`` by Eclips4 · Pull Request #120088 · python/cpython
Conversation
Eclips4
commented
Jun 5, 2024
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
CharlieZhao95 reacted with thumbs up emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for the review, Nikita!
|
sobolevn reacted with heart emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks @Eclips4 for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13.
🐍🍒⛏🤖
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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 reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
sobolevn
sobolevn approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|