This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author moi90
Recipients andrei.avk, iritkatriel, jbw, kj, moi90, serhiy.storchaka
Date 2021-10-26.07:42:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635234134.93.0.959501296489.issue43656@roundup.psfhosted.org>
In-reply-to
Content
Irit, I'm unsure about the wording. Something like ":meth:`__repr__` should always succeed, even if errors prevent a full description of the object."? "... even if the object is only partly initialized."?

Andrei, I think you can not simply omit the first argument. For virtually all methods, `self` is an important value for debugging. It could be omitted for __init__, but that would break consistency. Also, __init__ could call other methods that help initialize the object and therefore also deal with partly initialized objects.

I really think one important part of the solution to this problem is making people aware, that under some rare conditions, repr might receive a partly initialized object.

I'm also still convinced that the other part of the solution is a way to customize the behavior of StackSummary.extract and friends.
Context: I have written a tool (https://github.com/moi90/experitur) to run batches of (machine learning) experiments (so it is not interactive). In case of an error, the traceback is dumped into a file, together with the respective local variables (using `traceback.TracebackException.from_exception(...).format()`). I want this to succeed *in any case*, even if I was too ignorant to implement correct `__repr__`s in my experiment code (which is mostly on-time-use, so why should I care).

In the end, this whole problem only affects users of `capture_locals=True`, so we could just change the semantics of this parameter a bit:
False: do nothing, True: use repr (as before), <any callable>: use this callable to convert the value to a string.
This way, we could avoid adding an additional parameter to many of the methods in traceback AND give users an easy way to customize exception formatting for easy debugging.
History
Date User Action Args
2021-10-26 07:42:15moi90setrecipients: + moi90, serhiy.storchaka, iritkatriel, kj, andrei.avk, jbw
2021-10-26 07:42:14moi90setmessageid: <1635234134.93.0.959501296489.issue43656@roundup.psfhosted.org>
2021-10-26 07:42:14moi90linkissue43656 messages
2021-10-26 07:42:14moi90create