Repository navigation
refactor: walk tracebacks by attribute in error_already_set::what() - #6228
Merged
Merged
Conversation
Read tb_next, tb_frame, f_back, co_filename and co_name through attribute access and use the public PyFrame_GetCode/PyFrame_GetLineNumber functions, instead of poking traceback, frame and code object struct fields, which are not part of the stable ABI. See pybind#6104 (B6). Assisted-by: ClaudeCode:claude-opus-5-5
— codex GPT-6 on behalf of Ralf — Document that failed notes and traceback attribute lookups silently discard all secondary exception types, including KeyboardInterrupt and SystemError. Also note the audit hooks triggered by tb_frame access.
Collaborator
|
Commit e76bfb4 documents a known flaw in exception formatting: secondary exceptions from these attribute lookups are silently discarded, regardless of type — including The flaw predates this PR in the I considered two possible remedies:
However, I decided resolving this is beyond the scope of this PR. |
rwgk
approved these changes
Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 AI text below 🤖
Description
error_already_set::what()builds itsAt:section by reading traceback, frame, and code object struct fields directly. This PR readstb_next,tb_frame,f_back,co_filename, andco_nameby attribute access instead, and uses the publicPyFrame_GetCode/PyFrame_GetLineNumber.py::objecthandles the reference counts. If an attribute lookup fails, the error is cleared and the walk stops. The output does not change. The PyPy/GraalPy guard stays as it is.This comes from finding B6 in #6104. It is groundwork for stable-ABI support, but it is useful by itself because it removes a dependency on internal object layouts.
The existing tests checked the file, line, and function names of a multi-frame traceback only on Python < 3.12. A new test,
test_error_already_set_what_traceback, checks them for a nested Python call on all CPython versions. It also passes with the old code.Suggested changelog entry:
error_already_set::what()now walks the traceback through attribute access and public frame functions instead of reading object struct fields.