Mark Dickinson <dicki...@gmail.com> added the comment: > 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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue7279> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com