-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
gh-111922: Allow Using a Minimal Proxy for TracebackException.exc_type #112324
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
| self.addCleanup(sys.path.pop) | ||
|
|
||
| if not mod_name: | ||
| mod_name = ''.join(random.choices(string.ascii_letters, k=16)) |
There was a problem hiding this comment.
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?
Lib/test/test_traceback.py
Outdated
| def __repr__(self) -> str: | ||
| raise Exception("Unrepresentable") | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lib/traceback.py
Outdated
| raise ValueError(f'unsupported exc_type {exc_type!r}') | ||
|
|
||
|
|
||
| def _match_class(exc_type, *expected): |
There was a problem hiding this comment.
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.
|
I'm closing this in favor of gh-112333. |
Passing a proxy for exc_type is helpful when the
TracebackExceptionis 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
_xxsubinterpretersmodule I'm propagating exceptions via a pickledTracebackExceptionand 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.