STINNER Victor <> added the comment:

Stefan Behnel: "I added this assertion exactly for the purpose of finding this 
kind of bug. It means that some code tried to look up an attribute with a live 
exception set, which previously could swallow the exception in certain 
situations, and even if not, it is always the wrong thing to do."

The assertion failure is a little bit "far" from the bug: would it make sense 
to add "assert(!PyErr_Occurred());" to the entry point of:

* PyObject_HasAttr()
* PyObject_SetAttr()
* PyObject_SetAttrString()
* _PyObject_SetAttrId()
* type_getattro()
* slot_tp_getattr_hook()
* and other similar functions?

A few years ago, I added "assert(!PyErr_Occurred());" to the entry point of C 
functions which can call arbitrary code like _PyEval_EvalFrameDefault(), 
PyObject_Call(), etc. It helped to find many bugs.


Python tracker <>
Python-bugs-list mailing list

Reply via email to