Stefan Behnel added the comment:

> Is it correct to call _PyType_Lookup() with an exception set?

The general rule of thumb is that it's not safe to call any user code with a 
live exception set, and lookups can call into user code.

I quickly looked through all occurrences (there aren't that many actually), and 
they all seem be be called from a context where a live exception would be wrong.

> Perhaps we should save a current exception before calling find_name_in_mro() 
> and restore it after.

I thought about that, too, but it feels wrong. This just shouldn't be 
necessary. It's ok to save away exceptions in exception related code, but 
general purpose code shouldn't have to assume that it gets called with a live 
exception.

> Or just add assert(!PyErr_Occurred()) at the begin of find_name_in_mro().

That would catch the error at hand. The only concern is backwards 
compatibility. But it's easy to argue that it's the foreign code that is broken 
in this case (as show-cased by cElementTree) and clearly needs fixing if this 
occurs. An assert() seems like a reasonable way to catch this kind of bug, at 
least in a debug build.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31336>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to