[ python-Bugs-1275608 ] dict key comparison swallows exceptions

SourceForge.net noreply at sourceforge.net
Thu Jun 1 17:56:12 CEST 2006

Bugs item #1275608, was opened at 2005-08-29 06:30
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 

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: 5
Submitted By: Armin Rigo (arigo)
>Assigned to: Nobody/Anonymous (nobody)
Summary: dict key comparison swallows exceptions

Initial Comment:
This is an old one that has just biten again and cost a
lot of debugging time again: the dict lookup function
swallows all errors during key comparison.  This is bad
in itself, but if the current stack depth is just wrong
then *any* comparison will raise a RuntimeError and
lookup will pretend that the dictionary is essentially
empty.  The attached sample program shows this and
crashes with a KeyError instead of a RuntimeError.

While at the C level there is a basic compatibility
problem involved (PyDict_GetItem() not allowed to raise
any exception -- see
I think it should be possible to improve the situation
on the Python interface.  Unless someone points me to
something I missed, I plan to come up with a patch that
changes the internal dict functions (including
lookdict()) to let exceptions pass through, and have
the exceptions swallowed only by the PyDict_*() API
functions that require it.

The possible (remote) incompatibility here is existing
code relying on the exceptions being swallowed --
either Python code, or C code using PyObject_GetItem()
or PyMapping_GetItemString().  Such code deserves to be
shot down in my opinion.

Assigned to mwh for his feedback (not because I want
him to write the patch!).


>Comment By: Tim Peters (tim_one)
Date: 2006-06-01 11:56

Logged In: YES 

Patch 1497053 was checked in as revision 46589 of the trunk
for Python 2.5, so closing this.  Because it changes
semantics, it should not be backported to 2.4.


Comment By: Armin Rigo (arigo)
Date: 2006-05-29 12:55

Logged In: YES 

Proposed patch #1497053.


You can respond by visiting: 

More information about the Python-bugs-list mailing list