Skip to content

Commit 20b73c3

Browse files
committed
Fix decimal and docs as well
1 parent b9cde10 commit 20b73c3

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

Doc/library/stdtypes.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,9 @@ Here are the rules in detail:
692692
as ``-hash(-x)``. If the resulting hash is ``-1``, replace it with
693693
``-2``.
694694

695-
- The particular values ``sys.hash_info.inf``, ``-sys.hash_info.inf``
696-
and ``sys.hash_info.nan`` are used as hash values for positive
697-
infinity, negative infinity, or nans (respectively). (All hashable
698-
nans have the same hash value.)
695+
- The particular values ``sys.hash_info.inf`` and ``-sys.hash_info.inf``
696+
are used as hash values for positive
697+
infinity or negative infinity (respectively).
699698

700699
- For a :class:`complex` number ``z``, the hash values of the real
701700
and imaginary parts are combined by computing ``hash(z.real) +
@@ -740,7 +739,7 @@ number, :class:`float`, or :class:`complex`::
740739
"""Compute the hash of a float x."""
741740

742741
if math.isnan(x):
743-
return sys.hash_info.nan
742+
return id(x)
744743
elif math.isinf(x):
745744
return sys.hash_info.inf if x > 0 else -sys.hash_info.inf
746745
else:

Lib/_pydecimal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def __hash__(self):
951951
if self.is_snan():
952952
raise TypeError('Cannot hash a signaling NaN value.')
953953
elif self.is_nan():
954-
return _PyHASH_NAN
954+
return id(self)
955955
else:
956956
if self._sign:
957957
return -_PyHASH_INF

Modules/_decimal/_decimal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4536,7 +4536,6 @@ _dec_hash(PyDecObject *v)
45364536
#error "No valid combination of CONFIG_64, CONFIG_32 and _PyHASH_BITS"
45374537
#endif
45384538
const Py_hash_t py_hash_inf = 314159;
4539-
const Py_hash_t py_hash_nan = 0;
45404539
mpd_uint_t ten_data[1] = {10};
45414540
mpd_t ten = {MPD_POS|MPD_STATIC|MPD_CONST_DATA,
45424541
0, 2, 1, 1, ten_data};
@@ -4555,7 +4554,7 @@ _dec_hash(PyDecObject *v)
45554554
return -1;
45564555
}
45574556
else if (mpd_isnan(MPD(v))) {
4558-
return py_hash_nan;
4557+
return (Py_hash_t) v;
45594558
}
45604559
else {
45614560
return py_hash_inf * mpd_arith_sign(MPD(v));

0 commit comments

Comments
 (0)