Skip to content

Add traceback.TracebackException.__traceback__ #111918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ericsnowcurrently opened this issue Nov 9, 2023 · 2 comments
Closed

Add traceback.TracebackException.__traceback__ #111918

ericsnowcurrently opened this issue Nov 9, 2023 · 2 comments
Labels
3.13 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

ericsnowcurrently commented Nov 9, 2023

Feature or enhancement

The traceback object passed to traceback.TracebackException is converted to StackSummary object. That is exposed as the stack attribute of the new TracebackException object.

I'd like to also expose that as __traceback__. Why? To allow TracebackException to work better as a drop-in replacement proxy for an exception object. __traceback__ is the only standard exception attribute that is not found on TracebackException.

This does imply that we may also want StackSummary/FrameSummary to likewise work as a drop-in replacement for types.TracebackType. For some prior discussion about that, see #74764 (comment).

(FWIW, I didn't find any discussion on why __traceback__ wasn't added when all the other exception attributes were. I'm guessing it was an oversight, falling outside the TracebackException use cases people were thinking about at the time.)

@ericsnowcurrently ericsnowcurrently added type-feature A feature request or enhancement stdlib Python modules in the Lib dir 3.13 bugs and security fixes labels Nov 9, 2023
@ericsnowcurrently
Copy link
Member Author

Also see #111921 (comment).

@ericsnowcurrently
Copy link
Member Author

TracebackException isn't meant to represent an exception. Instead, it's purpose is to facilitate formatting the exception for "error display". Thus, there isn't much point to adding __traceback__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant