| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1638151 commit 3ef1368
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,20 +90,7 @@ Notes for type implementers | |||
| 90 | 90 | ||
| 91 | 91 | Implementers should be careful to make equal numbers equal and hash | |
| 92 | 92 | them to the same values. This may be subtle if there are two different | |
| 93 | - extensions of the real numbers. For example, :class:`fractions.Fraction` | ||
| 94 | - implements :func:`hash` as follows:: | ||
| 95 | - | ||
| 96 | - def __hash__(self): | ||
| 97 | - if self.denominator == 1: | ||
| 98 | - # Get integers right. | ||
| 99 | - return hash(self.numerator) | ||
| 100 | - # Expensive check, but definitely correct. | ||
| 101 | - if self == float(self): | ||
| 102 | - return hash(float(self)) | ||
| 103 | - else: | ||
| 104 | - # Use tuple's hash to avoid a high collision rate on | ||
| 105 | - # simple fractions. | ||
| 106 | - return hash((self.numerator, self.denominator)) | ||
| 93 | + extensions of the real numbers. See also :ref:`numeric-hash`. | ||
| 107 | 94 | ||
| 108 | 95 | ||
| 109 | 96 | Adding More Numeric ABCs | |
| Back | FazBrowse Home | New Git URL |
0 commit comments