Skip to content

gh-102791: allow non-fractional decimal.Decimals to be interpreted as integers #102794

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

Closed

Conversation

chrisnovakovic
Copy link

@chrisnovakovic chrisnovakovic commented Mar 17, 2023

Prior to gh-11952, several standard library functions that expected integer arguments would nevertheless silently accept (and truncate) non-integer arguments. This behaviour was deprecated in gh-11952, and removed in gh-15636.

However, it may be possible to interpret some non-integer numeric types (such as decimal.Decimals) 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.

…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.
@ghost
Copy link

ghost commented Mar 17, 2023

All commit authors signed the Contributor License Agreement.
CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants