diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2021-04-22 15:34:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-22 15:34:57 (GMT) |
commit | a07da09ad5bd7d234ccd084a3a0933c290d1b592 (patch) | |
tree | 8c1ab67575527bd5c0c9452a74458ad5a29a1d08 /Doc/library | |
parent | accea7dc2bd30a6e8e1b0334acfca9585cbd7f8a (diff) | |
download | cpython-a07da09ad5bd7d234ccd084a3a0933c290d1b592.zip cpython-a07da09ad5bd7d234ccd084a3a0933c290d1b592.tar.gz cpython-a07da09ad5bd7d234ccd084a3a0933c290d1b592.tar.bz2 |
bpo-43475: Fix worst case collision behavior for NaN instances (GH-25493)
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/stdtypes.rst | 9 | ||||
-rw-r--r-- | Doc/library/sys.rst | 2 |
2 files changed, 5 insertions, 6 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 68b6050..b83d0d8 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -692,10 +692,9 @@ Here are the rules in detail: as ``-hash(-x)``. If the resulting hash is ``-1``, replace it with ``-2``. -- The particular values ``sys.hash_info.inf``, ``-sys.hash_info.inf`` - and ``sys.hash_info.nan`` are used as hash values for positive - infinity, negative infinity, or nans (respectively). (All hashable - nans have the same hash value.) +- The particular values ``sys.hash_info.inf`` and ``-sys.hash_info.inf`` + are used as hash values for positive + infinity or negative infinity (respectively). - For a :class:`complex` number ``z``, the hash values of the real and imaginary parts are combined by computing ``hash(z.real) + @@ -740,7 +739,7 @@ number, :class:`float`, or :class:`complex`:: """Compute the hash of a float x.""" if math.isnan(x): - return sys.hash_info.nan + return super().__hash__() elif math.isinf(x): return sys.hash_info.inf if x > 0 else -sys.hash_info.inf else: diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index e431d1b..fe1cca1 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -855,7 +855,7 @@ always available. +---------------------+--------------------------------------------------+ | :const:`inf` | hash value returned for a positive infinity | +---------------------+--------------------------------------------------+ - | :const:`nan` | hash value returned for a nan | + | :const:`nan` | (this attribute is no longer used) | +---------------------+--------------------------------------------------+ | :const:`imag` | multiplier used for the imaginary part of a | | | complex number | |