-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Fraction wrongfully gets casted into float when given as argument to __rpow__ #119189
Comments
I'm investigating this. |
Reproduced under Linux (Ubuntu). I am working on a Fix (I'm in the sprint workshop) |
It's a mistake in the implementation of It does something similar when a |
Is anyone working on a fix? If not, this is an easy one, I can do it. I worry slightly about possible breakage of existing code, but:
|
@MojoVampire I am working on a fix I'm in the cpython sprint. |
@zitterbewegung: Same. I'm the guy standing up cause my back is borked. Fix is pretty easy:
replacing the existing final line. Tests are always the pain. I'll review when you're done. |
For context: I stumbled over the bug when implementing a wrapper number class for exact precision arithmetic that holds the data as a symbolic expression (so e.g. irrational numbers can be used in calculations without error). The class is designed to work with all builtin number types, e.g. a = Fraction(1, 3)
b = ExactNumber(Fraction(1, 2))
print(a**b)
My class is built on the sympy package that does similar things on its own, so this should also be relevant to them. Best, |
I worked on this today. The issue itself may be not difficult, but I noticed that tests do not cover many cases in mixed Fraction arithmetic. #119236 adds many new tests, so we will see what other side effect our changes can cause. |
@serhiy-storchaka I will look at this with @MojoVampire to see if there are any additional issues. |
I'd suggest the news entry simplify to something like:
Keeps it focused on what was fixed. |
With this fix I see a test failure when manually putting in the new test_fractions code in ======================================================================
|
Looks like a mistake in the test (or if you prefer, a test tailored to the old behavior). The
and the test expects |
…GH-119236) (cherry picked from commit fe67af1) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…GH-119236) (cherry picked from commit fe67af1) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…thonGH-119298) (cherry picked from commit 10b1bd9) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…thonGH-119298) (cherry picked from commit 10b1bd9) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
The new tests were purposed to fail with this change. They were added so that we can see what effect the change has and decide whether it is correct. If some visible changes are not correct, we should find other fixes for such cases. I have other changes for mixed Fraction arithmetic, but I am not sure that they should be backported, so I'll create a separate PR. |
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.
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>
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>
See also #119838. |
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.
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.
Bug report
Bug description:
When using the
**
operator with a Fraction as a base and an object that implements__rpow__
as an exponent the fraction gets wrongfully casted into a float before being passed to__rpow__
Expected Output
Actual Output:
Tested with Python 3.12.3
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
The text was updated successfully, but these errors were encountered: