[New-bugs-announce] [issue32696] Fix pickling exceptions with multiple arguments
Ofer
report at bugs.python.org
Sun Jan 28 11:15:55 EST 2018
New submission from Ofer <horowitz.ofer at gmail.com>:
Pickling exceptions fails when a custom exception class requires multiple arguments.
import pickle
class MultipleArgumentsError(Exception):
def __init__(self, a, b):
self.a = a
self.b = b
pickle.loads(pickle.dumps(MultipleArgumentsError('a', 'b')))
this code produces the following error:
Traceback (most recent call last):
File "/tmp/multiple_arguments_exception.py", line 8, in <module>
pickle.loads(pickle.dumps(MultipleArgumentsError('a', 'b')))
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1388, in loads
return Unpickler(file).load()
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1139, in load_reduce
value = func(*args)
TypeError: __init__() takes exactly 3 arguments (2 given)
The same error occurs when using a built-in module like subprocess:
>>> import subprocess, pickle
>>> try:
... subprocess.check_call(['python', '-c', 'raise SystemExit(1)'])
... except Exception as e:
... pickle.loads(pickle.dumps(e))
...
Related issue: https://bugs.python.org/issue1692335
----------
components: Interpreter Core
messages: 310963
nosy: alexandre.vassalotti, georg.brandl, jason.coombs, sbt, slallum, zseil
priority: normal
severity: normal
status: open
title: Fix pickling exceptions with multiple arguments
type: behavior
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32696>
_______________________________________
More information about the New-bugs-announce
mailing list