{{ message }}
bpo-37999: No longer use __int__ in implicit integer conversions.#15636
Merged
serhiy-storchaka merged 6 commits intoMay 26, 2020
Merged
bpo-37999: No longer use __int__ in implicit integer conversions.#15636serhiy-storchaka merged 6 commits into
serhiy-storchaka merged 6 commits into
Conversation
Only __index__ should be used to make integer conversions lossless.
serhiy-storchaka
commented
Sep 1, 2019
mdickinson
reviewed
May 26, 2020
656c19e to
49aa158
Compare
May 26, 2020 09:38
mdickinson
reviewed
May 26, 2020
mdickinson
approved these changes
May 26, 2020
Member
There was a problem hiding this comment.
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?
Sorry, something went wrong.
Member
Author
Yes, it is correct. |
Sorry, something went wrong.
This was referenced Mar 17, 2023
chrisnovakovic
added a commit
to chrisnovakovic/cpython
that referenced
this pull request
Mar 17, 2023
…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.
1 task
bkeryan
added a commit
to bkeryan/hightime
that referenced
this pull request
Mar 26, 2025
`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
1 task
tkrebes
pushed a commit
to ni/hightime
that referenced
this pull request
Apr 2, 2025
* 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.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.
Only
__index__should be used to make integer conversions lossless.https://bugs.python.org/issue37999