Skip to content
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

gh-119189: Fix the fraction module so that __rpow__ works on arbitrary classes. #119242

Merged
merged 14 commits into from
May 31, 2024

Conversation

zitterbewegung
Copy link
Contributor

@zitterbewegung zitterbewegung commented May 20, 2024

gh-119189: Fix the fraction module so that rpow works on arbitrary classes.

 The fraction module implicitly casted float if __rpow__ was implemented in your class when raising a fraction to a power. Now we replace the cast to float and instead check if it is a float or complex  and if the class isn't it will raise an exception.

@zitterbewegung zitterbewegung changed the title Fix the fraction module so that __rpow__ works on arbitrary classes. gh-119189: Fix the fraction module so that __rpow__ works on arbitrary classes. May 20, 2024
The fraction module implicitly casted float if __rpow__ was implemented in your class when raising a fraction to a power. Now it isn't done but will raise an exception if __rpow__ isn't implemented.
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Please update tests.

Also, I think that the text of the NEWS entry should be rewritten. It's hard to understand right now, I'm not even sure if it's correct at all.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

Please update tests and rewrite the NEWS entry.

@bedevere-app
Copy link

bedevere-app bot commented May 22, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@zitterbewegung
Copy link
Contributor Author

zitterbewegung commented May 25, 2024

Okay I will update tests.

@zitterbewegung
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented May 28, 2024

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from serhiy-storchaka May 28, 2024 12:20
@serhiy-storchaka
Copy link
Member

Tests are still failing. You have to make them pass.

@zitterbewegung
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented May 29, 2024

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

@zitterbewegung
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

bedevere-app bot commented May 30, 2024

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from serhiy-storchaka May 30, 2024 00:28
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your contribution @zitterbewegung.

@serhiy-storchaka serhiy-storchaka merged commit b9965ef into python:main May 31, 2024
33 checks passed
@serhiy-storchaka serhiy-storchaka added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels May 31, 2024
@miss-islington-app
Copy link

Thanks @zitterbewegung for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @zitterbewegung for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 31, 2024
When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
(cherry picked from commit b9965ef)

Co-authored-by: Joshua Herman <30265+zitterbewegung@users.noreply.github.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 31, 2024
When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
(cherry picked from commit b9965ef)

Co-authored-by: Joshua Herman <30265+zitterbewegung@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented May 31, 2024

GH-119835 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label May 31, 2024
@bedevere-app
Copy link

bedevere-app bot commented May 31, 2024

GH-119836 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 31, 2024
@serhiy-storchaka
Copy link
Member

I consider this a bug fix.

noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
serhiy-storchaka pushed a commit that referenced this pull request Jul 16, 2024
…-119835)

When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
(cherry picked from commit b9965ef)

Co-authored-by: Joshua Herman <30265+zitterbewegung@users.noreply.github.com>
serhiy-storchaka pushed a commit that referenced this pull request Jul 16, 2024
…-119836)

When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
(cherry picked from commit b9965ef)

Co-authored-by: Joshua Herman <30265+zitterbewegung@users.noreply.github.com>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
When using the ** operator or pow() with Fraction as the base
and an exponent that is not rational, a float, or a complex, the
fraction is no longer converted to a float.
scoder added a commit to scoder/quicktions that referenced this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants