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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1757>
__________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com