Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bpo-23975: Correct conversion of Rational’s to float#25619

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mdickinson merged 10 commits intopython:mainfromskirpichev:fix-23975
Sep 4, 2022
Merged

bpo-23975: Correct conversion of Rational’s to float#25619

mdickinson merged 10 commits intopython:mainfromskirpichev:fix-23975
Sep 4, 2022

Conversation

@skirpichev
Copy link
Contributor

@skirpichevskirpichev commentedApr 26, 2021
edited by bedevere-bot
Loading

Also document that numerator/denominator properties are instances of the Integral.

This solution wassuggested by Paul Moore.

https://bugs.python.org/issue23975

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actionsgithub-actionsbot added the staleStale PR or inactive for long period of time. labelJun 3, 2021
Also document that numerator/denominator propertiesare instances of the Integral.
@skirpichev
Copy link
ContributorAuthor

@mdickinson, you are listed as an expert for the fractions module, could you review this little PR? (This, probably, lacks a test.)

@mdickinson
Copy link
Member

@skirpichev Seems like a reasonable approach to me. But as you say, it needs a test before it can go in. (There should be at leastsomething in the test suite that fails if thoseint conversions are removed.)

@skirpichev
Copy link
ContributorAuthor

But as you say, it needs a test before it can go in.

Ok, lets see how it looks.

@skirpichev
Copy link
ContributorAuthor

skirpichev commentedMar 20, 2022
edited
Loading

Hmm, unfortunately, there is a silent type-cast. I can adjust the test, but may be it does make sense to add

diff --git a/Lib/fractions.py b/Lib/fractions.pyindex f9ac882ec0..4a153ee8e3 100644--- a/Lib/fractions.py+++ b/Lib/fractions.py@@ -143,6 +143,10 @@ def __new__(cls, numerator=0, denominator=None, *, _normalize=True):         elif type(numerator) is int is type(denominator):             pass # *very* normal case+        elif (isinstance(numerator, numbers.Integral) and+            isinstance(denominator, numbers.Integral)):+            pass+         elif (isinstance(numerator, numbers.Rational) and             isinstance(denominator, numbers.Rational)):             numerator, denominator = (

... or I can just "fix" type of private_numerator/denominator properties in the test by monkey patching.

@skirpichev
Copy link
ContributorAuthor

@mdickinson, let me know if you have some objections for added tests (maybe Lib/test/test_abstract_numbers.py is the right place to this?). I've realized that there almost no tests for default methods of the numbers.py (#32022 address this issue, partially).

@mdickinsonmdickinson self-requested a reviewApril 12, 2022 10:25
@MaxwellDupre
Copy link
Contributor

The fix looks simple but where does the current implementation fail? Can you provide a test case such that the current fails but the after the fix the test succeeds?

@skirpichev
Copy link
ContributorAuthor

@MaxwellDupre, the added test should be such one. At least it was a failing test for the old main branch (~Apr 2021).

Copy link
Contributor

@MaxwellDupreMaxwellDupre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@github-actionsgithub-actionsbot removed the staleStale PR or inactive for long period of time. labelAug 6, 2022
@mdickinsonmdickinson added needs backport to 3.10only security fixes needs backport to 3.11only security fixes labelsSep 4, 2022
Copy link
Member

@mdickinsonmdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@mdickinsonmdickinson merged commit8464b75 intopython:mainSep 4, 2022
@miss-islington
Copy link
Contributor

Thanks@skirpichev for the PR, and@mdickinson for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-96556 is a backport of this pull request to the3.11 branch.

@bedevere-botbedevere-bot removed the needs backport to 3.11only security fixes labelSep 4, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestSep 4, 2022
…thonGH-25619)*pythongh-68163: Correct conversion of Rational instances to floatAlso document that numerator/denominator properties are instances of Integral.Co-authored-by: Mark Dickinson <dickinsm@gmail.com>(cherry picked from commit8464b75)Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@bedevere-botbedevere-bot removed the needs backport to 3.10only security fixes labelSep 4, 2022
@bedevere-bot
Copy link

GH-96557 is a backport of this pull request to the3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestSep 4, 2022
…thonGH-25619)*pythongh-68163: Correct conversion of Rational instances to floatAlso document that numerator/denominator properties are instances of Integral.Co-authored-by: Mark Dickinson <dickinsm@gmail.com>(cherry picked from commit8464b75)Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@skirpichevskirpichev deleted the fix-23975 branchSeptember 4, 2022 12:30
mdickinson pushed a commit that referenced this pull requestSep 4, 2022
GH-96557)*gh-68163: Correct conversion of Rational instances to floatAlso document that numerator/denominator properties are instances of Integral.Co-authored-by: Mark Dickinson <dickinsm@gmail.com>(cherry picked from commit8464b75)Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
pablogsal pushed a commit that referenced this pull requestSep 8, 2022
…H-25619) (#96556)Co-authored-by: Mark Dickinson <dickinsm@gmail.com>Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

2 more reviewers

@mdickinsonmdickinsonmdickinson approved these changes

@MaxwellDupreMaxwellDupreMaxwellDupre approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

7 participants

@skirpichev@mdickinson@MaxwellDupre@miss-islington@bedevere-bot@the-knights-who-say-ni@ezio-melotti

[8]ページ先頭

©2009-2025 Movatter.jp