gh-119189: Fix the power operator for Fraction (GH-119242)

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.
This commit is contained in:
Joshua Herman 2024-05-31 05:05:09 -05:00 committed by GitHub
parent dae0375bd9
commit b9965ef282
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 6 deletions

View file

@ -877,8 +877,10 @@ class Fraction(numbers.Rational):
# A fractional power will generally produce an
# irrational number.
return float(a) ** float(b)
else:
elif isinstance(b, (float, complex)):
return float(a) ** b
else:
return NotImplemented
def __rpow__(b, a):
"""a ** b"""