classification
Title: IDLE internals show up in tracebacks when returning objects that cannot be `repr`ed
Type: Stage: resolved
Components: IDLE Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: ppperry, terry.reedy
Priority: normal Keywords:

Created on 2018-09-23 18:39 by ppperry, last changed 2018-09-28 22:29 by terry.reedy. This issue is now closed.

Messages (2)
msg326172 - (view) Author: (ppperry) Date: 2018-09-23 18:39
>>> class NoRepr:
	def __repr__(self):
		raise ValueError
>>> NoRepr()
Traceback (most recent call last):
  File "<pyshell#44>", line 1, in <module>
    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.
msg326184 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-09-23 21:15
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 "<stdin>", line 1, in <module>
  File "<stdin>", 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'.
History
Date User Action Args
2018-09-28 22:29:08terry.reedysetstatus: open -> closed
resolution: not a bug
stage: resolved
2018-09-23 21:15:49terry.reedysetmessages: + msg326184
2018-09-23 18:39:03ppperrycreate