Issue 34779: IDLE internals show up in tracebacks when returning objects that cannot be repr
ed (original) (raw)
class NoRepr: def repr(self): raise ValueError NoRepr() Traceback (most recent call last): File "<pyshell#44>", line 1, in NoRepr() File "C:\Program Files\Python37\lib\idlelib\rpc.py", line 617, in displayhook text = repr(value) File "<pyshell#43>", line 3, in repr raise ValueError ValueError
What should happen in this case isn't exactly clear, but the current traceback is wrong in multiple ways.
The baseline for what should happen is what does happen in interactive python.exe.
class N: ... def repr(self): raise ValueError ... N() Traceback (most recent call last): File "", line 1, in File "", line 2, in repr ValueError
IDLE's Shell very intentionally improves on this by including the code, which would be present if one ran the code from a file. This is most definitely not a bug.
idlelib.run.cleanup_traceback removes internal items from the beginning and end of tracebacks (as long as something is left) but intentionally leaves them in the middle, as they may add useful information. (Situations like this are rare.) This is also not a bug. These details are not part of the language definition.
In this case, I think the extra line will on net be informative to beginners. But even if you disagree, there is no way for code to decide. I cannot imagine what else you think is 'wrong'.