Skip to content
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

gh-111922: Allow Using a Minimal Proxy for TracebackException.exc_type #112324

Conversation

ericsnowcurrently
Copy link
Member

@ericsnowcurrently ericsnowcurrently commented Nov 22, 2023

Passing a proxy for exc_type is helpful when the TracebackException is going to be serialized (e.g. pickle) and you don't want to serialize user-defined types.

(That's the concrete motivation for me. For the _xxsubinterpreters module I'm propagating exceptions via a pickled TracebackException and don't want to deal with unpickling a user-defined exception class in a different interpreter.)

Note that most of this PR is tests, including a bunch of coverage of existing behavior.

self.addCleanup(sys.path.pop)

if not mod_name:
mod_name = ''.join(random.choices(string.ascii_letters, k=16))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert that mod_name is not in sys.modules before we add it?

@@ -2713,6 +2732,7 @@ class Unrepresentable:
def __repr__(self) -> str:
raise Exception("Unrepresentable")


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Lib/traceback.py Outdated
raise ValueError(f'unsupported exc_type {exc_type!r}')


def _match_class(exc_type, *expected):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd pass expected as a tuple (single arg), same way that types are passed to isinstance, etc.

@ericsnowcurrently
Copy link
Member Author

I'm closing this in favor of gh-112333.

@ericsnowcurrently ericsnowcurrently deleted the traceback-support-exc_type-proxy branch November 28, 2023 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants