[New-bugs-announce] [issue1757] Decimal hash depends on current context
Mark Dickinson
report at bugs.python.org
Mon Jan 7 22:03:58 CET 2008
New submission from Mark Dickinson:
The value of the Decimal hash() depends on the current context:
>>> from decimal import *
>>> x = Decimal("123456789.1")
>>> hash(x)
1989332493
>>> getcontext().prec = 6
>>> hash(x)
-2034270682
This has nasty consequences; e.g.:
>>> s = set([x])
>>> x in s
True
>>> getcontext().prec = 28
>>> x in s
False
hashing a Decimal can also set flags in the context; again, I think
this is undesirable.
The cause of this bug is clear: __hash__ calls normalize, which rounds
its argument to the current context. I'll post a fix when I get around
to it.
----------
components: Library (Lib)
messages: 59492
nosy: marketdickinson
severity: normal
status: open
title: Decimal hash depends on current context
versions: Python 2.5, Python 2.6, Python 3.0
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1757>
__________________________________
More information about the New-bugs-announce
mailing list