Fix __notes__ from outermost exception shown on all exceptions in chain #3964
+42
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
__notes__from outermost exception shown on all exceptions in chain #3960 --Traceback.__notes__from the outermost exception was incorrectly displayed on every exception in a chained traceback.notesassignment (getattr(exc_value, "__notes__", ...)) from before thewhile Trueloop to inside it, so eachStackreads notes from its ownexc_valuerather than reusing the same list for all.Root Cause
In
Traceback.extract(), thenoteslist was read once from the initialexc_valuebefore the loop that walks__cause__/__context__. Since the samenotesreference was passed to everyStack, all exceptions in the chain incorrectly displayed the outermost exception's notes.Test plan
RuntimeError, notValueErrortest_notes_chained_exceptions-- notes on outer only, inner has nonetest_notes_on_each_chained_exception-- each exception has its own distinct notes🤖 Generated with Claude Code