Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-37999: No longer use __int__ in implicit integer conversions.#15636
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
bpo-37999: No longer use __int__ in implicit integer conversions. #15636
Uh oh!
There was an error while loading. Please reload this page.
Conversation
serhiy-storchaka commented Sep 1, 2019 • edited by bedevere-bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by bedevere-bot
Uh oh!
There was an error while loading. Please reload this page.
Only __index__ should be used to make integer conversions lossless.
Uh oh!
There was an error while loading. Please reload this page.
Lib/datetime.py Outdated
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.
Looks like there's an effort to keep things in alphabetical order here; maybe move _index to the right place with respect to that order?
656c19e to 49aa158CompareUh oh!
There was an error while loading. Please reload this page.
mdickinson left a comment • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
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.
LGTM; I'm happy to see this finally reach completion.
Not sure I like the EDIT: This has been changedOverflowError for large negative values for math.factorial: that seems like a case of the implementation details leaking into the API.
Just to be clear, this PR doesn't change the fact that PyNumber_Index can still return something that's an instance of a strict subclass of int. Is that correct?
serhiy-storchaka commented May 26, 2020
Yes, it is correct. |
…ted as integers Prior to pythongh-11952, several standard library functions that expected integer arguments would nevertheless silently accept (and truncate) non-integer arguments. This behaviour was deprecated in pythongh-11952, and removed in pythongh-15636. However, it may be possible to interpret some non-integer numeric types (such as `decimal.Decimal`s) as integers if they contain no fractional part. Implement `__index__` for `decimal.Decimal`, returning an integer representation of the value if it does not contain a fractional part or raising a `TypeError` if it does.
`datetime` used to accept objects that implement `__int__` or `__index__`, but in Python 3.10 it was changed to accept only `__index__`. python/cpython#15636
* hightime: Update Python versions in tox.ini * hightime: Update trove classifiers * hightime: More tox.ini updates * hightime: Use __index__ instead of __int__ `datetime` used to accept objects that implement `__int__` or `__index__`, but in Python 3.10 it was changed to accept only `__index__`. python/cpython#15636 * github: Update Python versions
Only
__index__should be used to make integer conversions lossless.https://bugs.python.org/issue37999