Last active
November 6, 2021 16:57
-
-
Save aaronchall/e1be52a7d4decaec6878ff1c58263d3f to your computer and use it in GitHub Desktop.
pickle demo
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
>>> class Error(Exception): | |
... def __init__(self, foo, bar): | |
... return super().__init__(foo, bar) | |
... | |
>>> Error('blah', 'blah') | |
Error('blah', 'blah') | |
>>> pickle.loads(pickle.dumps(Error('blah', 'blah'))) | |
Error('blah', 'blah') | |
Fails: | |
>>> class Error(Exception): | |
... def __init__(self, foo, bar): | |
... super().__init__((foo, bar)) | |
... | |
>>> import pickle; pickle.loads(pickle.dumps(Error('blah', 'blah'), protocol=pickle.HIGHEST_PROTOCOL)) | |
Traceback (most recent call last): | |
File "<stdin>", line 1, in <module> | |
TypeError: Error.__init__() missing 1 required positional argument: 'bar' | |
Sottile says due to Exception's reduce method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment