Bugs item #1163325, was opened at 2005-03-14 22:37
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1163325&group_id=5470

Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Marien Zwart (marienz)
Assigned to: Nobody/Anonymous (nobody)
Summary: "special" decimals aren't hashable

Initial Comment:
Python 2.4 (#1, Feb 22 2005, 15:02:34) 
[GCC 3.4.3-20050110 (Gentoo Linux 3.4.3.20050110,
ssp-3.4.3.20050110-0, pie-8.7 on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import decimal
>>> hash(decimal.NaN)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/lib/python2.4/decimal.py", line 720, in
__hash__
    i = int(self)
  File "/usr/lib/python2.4/decimal.py", line 1410, in
__int__
    return context._raise_error(InvalidContext)
  File "/usr/lib/python2.4/decimal.py", line 2215, in
_raise_error
    raise error, explanation
decimal.InvalidOperation

This behaviour doesn't match the comment in
decimal.py's __hash__:
# Decimal integers must hash the same as the ints
# Non-integer decimals are normalized and hashed as strings
# Normalization assures that hast(100E-1) == hash(10)

Would it make sense to wrap the int(self) in an except
block and return hash(str(self.normalize())) if this
raises?


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1163325&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to