[Python-Dev] Let's stop eating exceptions in dict lookup
Armin Rigo
arigo at tunes.org
Mon May 29 19:11:48 CEST 2006
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. 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.
A bientot,
Armin
More information about the Python-Dev
mailing list