Message101595
> I think hash(Decimal("snan")) should also succeed
On second thoughts, this would be bad, since it would lead to unpredictable results for sets of dicts containing a signaling nan:
>>> from decimal import Decimal
[69536 refs]
>>> s = Decimal('snan'); h = hash(s)
[69551 refs]
>>> {s, h+1} # can put most integers into a set with an sNaN
{Decimal('sNaN'), 373955814}
[69561 refs]
>>> {s, h} # but not if that integer hashes equal to the sNaN...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dickinsm/python/svn/py3k/Lib/decimal.py", line 864, in __eq__
ans = self._check_nans(other, context)
File "/Users/dickinsm/python/svn/py3k/Lib/decimal.py", line 746, in _check_nans
self)
File "/Users/dickinsm/python/svn/py3k/Lib/decimal.py", line 3842, in _raise_error
raise error(explanation)
decimal.InvalidOperation: sNaN
[69698 refs]
So if __eq__ with an sNaN raises an exception, there's little choice but to prohibit putting sNaNs into sets and dicts, and the obvious way to do this is to make __hash__ raise too. |
|
Date |
User |
Action |
Args |
2010-03-23 19:33:09 | mark.dickinson | set | recipients:
+ mark.dickinson, skrah |
2010-03-23 19:33:09 | mark.dickinson | set | messageid: <1269372789.24.0.707568342946.issue7279@psf.upfronthosting.co.za> |
2010-03-23 19:33:07 | mark.dickinson | link | issue7279 messages |
2010-03-23 19:33:07 | mark.dickinson | create | |
|