Martin <martin.schroe...@nerdluecht.de> added the comment:

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.

----------

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

Reply via email to