mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Bug #1163325: "special" decimals aren't hashable
This commit is contained in:
parent
141f41ae1a
commit
bea3f6f5c7
3 changed files with 10 additions and 0 deletions
|
|
@ -728,6 +728,10 @@ class Decimal(object):
|
|||
# Decimal integers must hash the same as the ints
|
||||
# Non-integer decimals are normalized and hashed as strings
|
||||
# Normalization assures that hast(100E-1) == hash(10)
|
||||
if self._is_special:
|
||||
if self._isnan():
|
||||
raise TypeError('Cannot hash a NaN value.')
|
||||
return hash(str(self))
|
||||
i = int(self)
|
||||
if self == Decimal(i):
|
||||
return hash(i)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue