[3.12] gh-119189: Fix the power operator for Fraction (GH-119242) (GH-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 b9965ef282)

Co-authored-by: Joshua Herman <30265+zitterbewegung@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2024-07-16 09:44:05 +02:00 committed by GitHub
parent b455a5a55c
commit d4f57ccc3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 6 deletions

View file

@ -825,8 +825,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"""