a == b
(a, b)
| 998 | return _hash_algorithm(self._numerator, self._denominator) |
| 999 | |
| 1000 | def __eq__(a, b): |
| 1001 | """a == b""" |
| 1002 | if type(b) is int: |
| 1003 | return a._numerator == b and a._denominator == 1 |
| 1004 | if isinstance(b, numbers.Rational): |
| 1005 | return (a._numerator == b.numerator and |
| 1006 | a._denominator == b.denominator) |
| 1007 | if isinstance(b, numbers.Complex) and b.imag == 0: |
| 1008 | b = b.real |
| 1009 | if isinstance(b, float): |
| 1010 | if math.isnan(b) or math.isinf(b): |
| 1011 | # comparisons with an infinity or nan should behave in |
| 1012 | # the same way for any finite a, so treat a as zero. |
| 1013 | return 0.0 == b |
| 1014 | else: |
| 1015 | return a == a.from_float(b) |
| 1016 | else: |
| 1017 | # Since a doesn't know how to compare with b, let's give b |
| 1018 | # a chance to compare itself with a. |
| 1019 | return NotImplemented |
| 1020 | |
| 1021 | def _richcmp(self, other, op): |
| 1022 | """Helper for comparison operators, for internal use only. |
nothing calls this directly
no test coverage detected