mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00:00
Make Fraction to complex comparisons with <=, <, >= or > raise TypeError.
This commit is contained in:
parent
355adc5a45
commit
71b7fac07b
2 changed files with 19 additions and 4 deletions
|
@ -511,8 +511,10 @@ class Fraction(Rational):
|
|||
if isinstance(other, Rational):
|
||||
return op(self._numerator * other.denominator,
|
||||
self._denominator * other.numerator)
|
||||
if isinstance(other, numbers.Complex) and other.imag == 0:
|
||||
other = other.real
|
||||
# comparisons with complex should raise a TypeError, for consistency
|
||||
# with int<->complex, float<->complex, and complex<->complex comparisons.
|
||||
if isinstance(other, complex):
|
||||
raise TypeError("no ordering relation is defined for complex numbers")
|
||||
if isinstance(other, float):
|
||||
if math.isnan(other) or math.isinf(other):
|
||||
return op(0.0, other)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue