Make Fraction to complex comparisons with <=, <, >= or > raise TypeError.

This commit is contained in:
Mark Dickinson 2010-03-27 11:09:29 +00:00
parent 355adc5a45
commit 71b7fac07b
2 changed files with 19 additions and 4 deletions

View file

@ -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)