[Python-Dev] Let's stop eating exceptions in dict lookup

Guido van Rossum guido at python.org
Mon May 29 21:34:30 CEST 2006


On 5/29/06, Armin Rigo <arigo at tunes.org> wrote:
> Hi all,
>
> I've finally come around to writing a patch that stops dict lookup from
> eating all exceptions that occur during lookup, like rare bugs in user
> __eq__() methods.  After another 2-hours long debugging session that
> turned out to be caused by that, I had a lot of motivation.
>
>   http://python.org/sf/1497053
>
> The patch doesn't change the PyDict_GetItem() interface, which is the
> historical core of the problem.  It works around this issue by just
> moving the exception-eating bit there instead of in lookdict(), so it
> gets away with changing only dictobject.c (plus ceval.c's direct usage
> of ma_lookup for LOAD_GLOBAL).  The benefit of this patch is that all
> other ways to work with dicts now correctly propagate exceptions, and
> this includes all the direct manipulation from Python code (including
> 'x=d[key]').
>
> The reason I bring this up here is that I'm going to check it in 2.5,
> unless someone seriously objects.

+1, as long as (as you seem to imply) PyDict_GetItem() still swallows
all exceptions.

> About the objection "we need a better
> fix, PyDict_GetItem() should really be fixed and all its usages
> changed": this would be good, and also require some careful
> compatibility considerations, and quite some work in total; it would
> also give a patch which is basically a superset of mine, so I don't
> think I'm going in the wrong direction there.

Fixing PyDict_GetItem() is a py3k issue, I think. Until then, there
are way too many uses. I wouldn't be surprised if after INCREF and
DECREF it's the most commonly used C API method...

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list