Author mark.dickinson
Recipients mark.dickinson, skrah
Date 2010-03-23.19:33:06
SpamBayes Score 5.89357e-07
Marked as misclassified No
Message-id <1269372789.24.0.707568342946.issue7279@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2010-03-23 19:33:09mark.dickinsonsetrecipients: + mark.dickinson, skrah
2010-03-23 19:33:09mark.dickinsonsetmessageid: <1269372789.24.0.707568342946.issue7279@psf.upfronthosting.co.za>
2010-03-23 19:33:07mark.dickinsonlinkissue7279 messages
2010-03-23 19:33:07mark.dickinsoncreate