[issue33576] Remove exception wrapping from __set_name__ calls

Carl Meyer report at bugs.python.org
Sat May 19 11:47:22 EDT 2018


Carl Meyer <carl at oddbird.net> added the comment:

Awkwardly, the motivating use case in issue21145 is a TypeError that we wanted to raise within __set_name__, and not have replaced. It feels a little ugly to special case TypeError this way. 

I like the _PyErr_TrySetFromCause idea. That function is a bit ugly too, in the way it has to try and sniff out whether an exception has extra state or is safe to copy and add extra context to. But in practice I think the results would be pretty good here. Most of the time you’d get the original exception but with added useful context; occasionally for some exception types you might just not get the extra context. But as long as TypeError falls in the former category it would help with the worst case. 

I’ll look at using that in the PR.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33576>
_______________________________________


More information about the Python-bugs-list mailing list