Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bea3f6f5
Commit
bea3f6f5
authored
Mar 15, 2005
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug #1163325: "special" decimals aren't hashable
parent
141f41ae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
0 deletions
+10
-0
Lib/decimal.py
Lib/decimal.py
+4
-0
Lib/test/test_decimal.py
Lib/test/test_decimal.py
+3
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/decimal.py
View file @
bea3f6f5
...
...
@@ -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
)
...
...
Lib/test/test_decimal.py
View file @
bea3f6f5
...
...
@@ -811,6 +811,9 @@ class DecimalUsabilityTest(unittest.TestCase):
hash
(
Decimal
(
23
))
#the same hash that to an int
self
.
assertEqual
(
hash
(
Decimal
(
23
)),
hash
(
23
))
self
.
assertRaises
(
TypeError
,
hash
,
Decimal
(
'NaN'
))
self
.
assert_
(
hash
(
Decimal
(
'Inf'
)))
self
.
assert_
(
hash
(
Decimal
(
'-Inf'
)))
def
test_min_and_max_methods
(
self
):
...
...
Misc/NEWS
View file @
bea3f6f5
...
...
@@ -86,6 +86,9 @@ Extension Modules
Library
-------
- Bug #1163325: Decimal infinities failed to hash. Attempting to
hash a NaN raised an InvalidOperation instead of a TypeError.
- Patch #918101: Add tarfile open mode r|* for auto-detection of the
stream compression; add, for symmetry reasons, r:* as a synonym of r.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment