Skip to content

Commit dc73c3c

Browse files
committed
Use existing pointer hash logic
1 parent 056a4f7 commit dc73c3c

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

Doc/library/stdtypes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ number, :class:`float`, or :class:`complex`::
739739
"""Compute the hash of a float x."""
740740

741741
if math.isnan(x):
742-
return id(x)
742+
return super().__hash__()
743743
elif math.isinf(x):
744744
return sys.hash_info.inf if x > 0 else -sys.hash_info.inf
745745
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 id(self)
954+
return super().__hash__()
955955
else:
956956
if self._sign:
957957
return -_PyHASH_INF

Modules/_decimal/_decimal.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4554,7 +4554,7 @@ _dec_hash(PyDecObject *v)
45544554
return -1;
45554555
}
45564556
else if (mpd_isnan(MPD(v))) {
4557-
return (Py_hash_t) v;
4557+
return _Py_HashPointer(v);
45584558
}
45594559
else {
45604560
return py_hash_inf * mpd_arith_sign(MPD(v));
@@ -5938,5 +5938,3 @@ PyInit__decimal(void)
59385938

59395939
return NULL; /* GCOV_NOT_REACHED */
59405940
}
5941-
5942-

Python/pyhash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static Py_ssize_t hashstats[Py_HASH_STATS_MAX + 1] = {0};
8686
8787
*/
8888

89+
Py_hash_t _Py_HashPointer(const void *);
90+
8991
Py_hash_t
9092
_Py_HashDouble(PyObject *inst, double v)
9193
{
@@ -97,7 +99,7 @@ _Py_HashDouble(PyObject *inst, double v)
9799
if (Py_IS_INFINITY(v))
98100
return v > 0 ? _PyHASH_INF : -_PyHASH_INF;
99101
else
100-
return (Py_hash_t) inst;
102+
return _Py_HashPointer(inst);
101103
}
102104

103105
m = frexp(v, &e);

0 commit comments

Comments
 (0)