Message392966
Pablo, unless you are suggesting rewriting IDLE's custom exception handing in C, I don't see how making it a single function would be an improvement. As long as it is Python code, the problem is accessing the message supplement.
After reading your comment, I agree that injecting Python code into the C exception handling is a bad idea. It also, I see now, not needed
run.print_exception first calls traceback.extract_tb (line 238). The doc says " It is useful for alternate formatting of stack traces", which IDLE does. print_exception next calls the undocumented traceback.print_list, which is format_list + print*. Finally, print_exception calls traceback.format_exception_only (line 2440), which returns a list of lines that is immediately printed.
So all IDLE needs is for format_exception_only to include the extra lines, either by default or by option. But it just calls TracebackException.format_exception)only, which call a private Python-coded function, which can only add the lines if accessible from Python-code.
Dennis cleverly pointed out that such access is available, even if awkwardly, by capturing the standard excepthook outout and keeping only the missing part. (test.support.captured_stderr just wraps io.StringIO as a context manager. IDLE can borrow and edits its code.)
Dennis, would you like to prepare a PR that follows the format_exception_only call with something like
if isinstance(typ, (AttributeError, NameError)):
lines.extend(extract_extra_message(<args>))
and a definition of the new function? (and a new test)? Or perhaps better, replace format_exception_only with a function that gets all lines at once.
Pablo, do any other exception types have such omitted help info? Do you have plans for any more? |
|
Date |
User |
Action |
Args |
2021-05-04 23:40:47 | terry.reedy | set | recipients:
+ terry.reedy, pablogsal, Dennis Sweeney, shreyanavigyan |
2021-05-04 23:40:47 | terry.reedy | set | messageid: <1620171647.48.0.323859008431.issue44026@roundup.psfhosted.org> |
2021-05-04 23:40:47 | terry.reedy | link | issue44026 messages |
2021-05-04 23:40:47 | terry.reedy | create | |
|