Skip to content

Instantly share code, notes, and snippets.

@aaronchall
Last active November 6, 2021 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronchall/e1be52a7d4decaec6878ff1c58263d3f to your computer and use it in GitHub Desktop.
Save aaronchall/e1be52a7d4decaec6878ff1c58263d3f to your computer and use it in GitHub Desktop.
pickle demo
>>> 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