Message405028
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. |
|
Date |
User |
Action |
Args |
2021-10-26 07:42:15 | moi90 | set | recipients:
+ moi90, serhiy.storchaka, iritkatriel, kj, andrei.avk, jbw |
2021-10-26 07:42:14 | moi90 | set | messageid: <1635234134.93.0.959501296489.issue43656@roundup.psfhosted.org> |
2021-10-26 07:42:14 | moi90 | link | issue43656 messages |
2021-10-26 07:42:14 | moi90 | create | |
|