You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The docs of "traceback.format_exception_only" is incorrect when the Exception has notes #109184
Format the exception part of a traceback using an exception value such as given by sys.last_value. The return value is a list of strings, each ending in a newline. Normally, the list contains a single string; however, for SyntaxError exceptions, it contains several lines that (when printed) display detailed information about where the syntax error occurred. The message indicating which exception occurred is the always last string in the list.
The last string isn't always the formatted Exception instance. Actually, the last string can be any arbitrary string if notes are added to the Exception, as demonstrated by the following example:
importtracebacke=ValueError("The error")
e.add_note("Notes:\n1. Part 1\n2. Part 2")
output=traceback.format_exception_only(e)
print(output)
The output is actually a list of 4 elements, with the message representing the raised Exception being in first position:
['ValueError: The error\n', 'Notes:\n', '1. Part 1\n', '2. Part 2\n']
Activity
terryjreedy commentedon Sep 9, 2023
@iritkatriel
iritkatriel commentedon Sep 9, 2023
Thank you. "Normally, the list contains a single string" is also no longer true.
pythongh-109184: traceback module doc is out of date w.r.t notes
iritkatriel commentedon Sep 9, 2023
Is this better? #109201
Delgan commentedon Sep 9, 2023
Looks good and accurate! Thanks for the update. 👍
gh-109184: update traceback module doc w.r.t notes (message is no lon…
pythongh-109184: update traceback module doc w.r.t notes (message is …
pythongh-109184: update traceback module doc w.r.t notes (message is …
[3.11] gh-109184: update traceback module doc w.r.t notes (message is…
[3.12] gh-109184: update traceback module doc w.r.t notes (message is…
pythongh-109184: update traceback module doc w.r.t notes (message is …