Closed
Description
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__
from fractions import Fraction
foo = Fraction(4, 3)
class One:
def __rpow__(self, other):
return other
bar = foo**One()
print(bar)
print(type(bar))
Expected Output
4/3
<class 'fractions.Fraction'>
Actual Output:
1.3333333333333333
<class 'float'>
Tested with Python 3.12.3
CPython versions tested on:
3.12
Operating systems tested on:
macOS
Linked PRs
- gh-119189: Add more tests for mixed Fraction arithmetic #119236
- gh-119189: Fix the fraction module so that __rpow__ works on arbitrary classes. #119242
- [3.13] gh-119189: Add more tests for mixed Fraction arithmetic (GH-119236) #119255
- [3.12] gh-119189: Add more tests for mixed Fraction arithmetic (GH-119236) #119256
- gh-119189: Add yet more tests for mixed Fraction arithmetic #119298
- [3.13] gh-119189: Add yet more tests for mixed Fraction arithmetic (GH-119298) #119346
- [3.12] gh-119189: Add yet more tests for mixed Fraction arithmetic (GH-119298) #119347
- [3.12] gh-119189: Fix the power operator for Fraction (GH-119242) #119835
- [3.13] gh-119189: Fix the power operator for Fraction (GH-119242) #119836