gh-154002: Do not wrap a constructor TypeError in pickle._Unpickler - #154003
Open
fedonman wants to merge 3 commits into
Open
gh-154002: Do not wrap a constructor TypeError in pickle._Unpickler#154003fedonman wants to merge 3 commits into
fedonman wants to merge 3 commits into
Conversation
…iate When a class constructor raised TypeError during old-style (INST/OBJ) unpickling, the pure-Python unpickler did `raise TypeError(msg, err.__traceback__)`, which stored the traceback object in the exception's args and performed no real chaining (__cause__ stayed None). Use `raise TypeError(msg) from err` instead. The C implementation is unaffected; it lets the original error propagate.
Contributor
Author
|
@zware part of EuroPython sprint. |
The prefix repeats the class name that the constructor TypeError already carries, and the C unpickler never wrapped the error, so letting the original propagate removes the traceback-in-args bug and the divergence at once.
_Unpickler._instantiate
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.
_instantiatewrapped a constructorTypeErrorin a new one, passing the traceback as asecond argument, so the traceback object ended up in
argsand there was no chaining.The wrapper is now gone and the original error propagates. Its purpose (743d17e, 1998)
was to name the class when
__getinitargs__returned something bogus, and the messagealready carries the class name in that case, so the prefix repeated it:
The C unpickler never wrapped the error, so this also removes the divergence between the
two implementations. Both now give the same result for a bad argument count and for a
TypeErrorraised inside the constructor body.The test asserts the original error reaches the caller unchanged. It fails on the
pure-Python unpickler without this change.
For the record, the traceback-in-
argspart is not from gh-102799 as the issue says. Itcomes from 26d95c3, where
raise T, V, tbbecameraise T(V, tb)rather thanraise T(V).with_traceback(tb). gh-102799 only changedsys.exc_info()[2]toerr.__traceback__._Unpicklermangles a constructorTypeError#154002