[issue43656] TracebackException or StackSummary.extract with capture_locals=True fail to catch exceptions raised by repr() on value of frame local variable in FrameSummary.__init__.

Andrei Kulakov report at bugs.python.org
Tue Oct 26 12:10:47 EDT 2021


Andrei Kulakov <andrei.avk at gmail.com> added the comment:

Martin: It's true that exceptions raised in other methods called from __init__ would still have this issue, but I feel like ~90% of it would be solved by the proposed fix.

It does introduce an inconsistency but it does so because it reflects the inconsistency of `self` being NOT initialized in __init__ and `self` being initialized in all other methods used after __init__. It makes intuitive sense that you don't get a repr of an object before it exists in a full state.

The doc fix is useful in itself, but I'm not sure it's enough given the issue reported by Joe with new students getting this error. When they get this error, they will not understand why it happens, what's the connection between the error and the argument that needs to be provided to fix it, and whether it's the correct fix or not.

If they *do* understand it, fixing the __repr__ is probably the best solution, and then no fix on our side is required.

My concern with adding a safe repr argument is that code using that argument can be copy pasted unknowingly and then it's not explicit/obvious that it will silence the errors raised due to broken __repr__'s. (including __repr__'s that are broken even outside of __init__ method).

If such an parameter is added, it's much better to make it a new parameter, to avoid backwards incompatible change, which means it can be backported.

----------

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


More information about the Python-bugs-list mailing list