diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2010-03-27 11:09:29 +0000 |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2010-03-27 11:09:29 +0000 |
commit | 71b7fac07ba978630844bdabee59492e329d036c (patch) | |
tree | aadf120def2251712083dbb70c803f53498447ff /Lib/fractions.py | |
parent | 355adc5a451ce3b22b66a3af883d35e89e2a0eab (diff) | |
download | cpython-git-71b7fac07ba978630844bdabee59492e329d036c.tar.gz |
Make Fraction to complex comparisons with <=, <, >= or > raise TypeError.
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r-- | Lib/fractions.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index a934389a37..7a3e5553c4 100644 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -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) |