Fix __tracebackhide__ not respected in ExceptionGroup sub-exception tracebacks#14649
Open
EternalRights wants to merge 2 commits into
Open
Fix __tracebackhide__ not respected in ExceptionGroup sub-exception tracebacks#14649EternalRights wants to merge 2 commits into
EternalRights wants to merge 2 commits into
Conversation
…racebacks ExceptionGroup tracebacks use the native style via traceback.format_exception. The top-level traceback gets filtered, but format_exception then walks each sub-exception's original __traceback__ and renders those frames unfiltered, so __tracebackhide__ set inside a sub-exception's call stack has no effect. Fix by building a traceback.TracebackException and filtering its stack in place, recursing into sub-exceptions and __cause__/__context__ chains. Original exception objects are not mutated. Closes pytest-dev#14036
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.
ExceptionGroup tracebacks use the native style, which calls
traceback.format_exceptionwith the group's traceback. The top-leveltraceback gets filtered for
__tracebackhide__, butformat_exceptionthenwalks each sub-exception's original
__traceback__and renders those framesunfiltered, so
__tracebackhide__set inside a sub-exception's call stack hasno effect.
Fix by building a
traceback.TracebackExceptionand filtering itsstackinplace, recursing into sub-exceptions and
__cause__/__context__chains. Theoriginal exception objects are not mutated. Native output style is kept.
Closes #14036