[ python-Bugs-212558 ] dictionary lookup does not check exceptions
SourceForge.net
noreply at sourceforge.net
Thu Dec 15 11:24:16 CET 2005
Bugs item #212558, was opened at 2000-08-23 14:24
Message generated for change (Comment added) made by arigo
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=212558&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: None
Status: Closed
Resolution: Fixed
Priority: 9
Submitted By: Jeremy Hylton (jhylton)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: dictionary lookup does not check exceptions
Initial Comment:
class BadDictKey:
def __hash__(self):
return hash(self.__class__)
def __cmp__(self, other):
if isinstance(other, self.__class__):
print "raising error"
raise RuntimeError, "gotcha"
return other
The dict lookup code does not check for hash or cmp functions raising an exception. This can lead to a variety of bogus behavior; e.g. the uncaught exception is noticed and raised for the next line.
>>> d = {}
>>> x1 = BadDictKey()
>>> x2 = BadDictKey()
>>> d[x1] = 1
>>> d[x2] = 2
raising error
>>> print d.keys()
Traceback (most recent call last):
File "/tmp/dicterr.py", line 8, in __cmp__
raise RuntimeError, "gotcha"
RuntimeError: gotcha
----------------------------------------------------------------------
>Comment By: Armin Rigo (arigo)
Date: 2005-12-15 10:24
Message:
Logged In: YES
user_id=4771
For future reference, the patch number is actually #401277.
----------------------------------------------------------------------
Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2000-08-31 19:05
Message:
Fixed by patch #101277, checked in as dictobject.c revision 2.63.
----------------------------------------------------------------------
Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2000-08-24 16:56
Message:
See patch #101277 for a proposed fix & discussion.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=212558&group_id=5470
More information about the Python-bugs-list
mailing list