-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-26680: Incorporate is_integer in all built-in and standard library numeric types #6121
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
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d80b017
bpo-26680: Adds support for int.is_integer() for compatibility with f…
rob-smallshire b46a9dc
bpo-26680: Adds a test to ensure that False.is_integer() and True.is_…
rob-smallshire 3b1677f
bpo-26680: Adds Real.is_integer() with a trivial implementation using…
rob-smallshire f78bf5c
bpo-26680: Adds Rational.is_integer which returns True if the denomin…
rob-smallshire 6a905a8
bpo-26680: Adds Integral.is_integer which always returns True.
rob-smallshire cc07ee5
bpo-26680: Adds tests for Fraction.is_integer called as an instance m…
rob-smallshire 3ae9866
bpo-26680: Updates documentation for Real.is_integer and built-ins in…
rob-smallshire 54ca820
bpo-26680: Adds Decimal.is_integer to the Python and C implementations.
rob-smallshire a9e364d
bpo-26680: Updates the ACKS file.
rob-smallshire 11db7f8
bpo-26680: NEWS entries for int, the numeric ABCs and Decimal.
rob-smallshire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-26680: Adds Rational.is_integer which returns True if the denomin…
…ator is one. This implementation assumes the Rational is represented in it's lowest form, as required by the class docstring.
- Loading branch information
commit f78bf5c9d726801e67ff1bd8d13797d77d4967b6
There are no files selected for viewing
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
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
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.
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.
Must
denominatorandnumeratoralways be fully reduced?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.
If not,
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.
Yes,
self.numeratorandself.denominatorwill always be relatively prime in normal use (and denominator will always be positive). Other parts of the fractions module assume this, so it's safe to just checkself.denominator == 1here.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.
This isn't about
Fractionand its implementation of the Rational API though - this is about whether the API mandates the implementation behaves this way.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.
Ah. I see the doc is
""".numerator and .denominator should be in lowest terms."""- so perhaps worth clarifying that denominator should always be positive too.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.
Yes, that docstring could definitely be improved. Apart from that clarification, we could do with a line or two describing what the
Rationalclass is actually for, rather than launching straight into a detail. But that's a job for a separate PR.