[New-bugs-announce] [issue40917] pickling exceptions with mandatory keyword args will traceback

Toshio Kuratomi report at bugs.python.org
Mon Jun 8 19:46:10 EDT 2020


New submission from Toshio Kuratomi <a.badger at gmail.com>:

I was trying to use multiprocessing (via a concurrent.futures.ProcessPoolExecutor) and encountered an error when pickling a custom Exception.  On closer examination I was able to create a simple test case that only involves pickle:


import pickle
class StrRegexError(Exception):
    def __init__(self, *, pattern):
        self.pattern = pattern

data = pickle.dumps(StrRegexError(pattern='test'))
instance = pickle.loads(data)


[pts/11 at peru /srv/ansible]$ python3.8 ~/p.py
Traceback (most recent call last):
  File "/home/badger/p.py", line 7, in <module>
    instance = pickle.loads(data)
TypeError: __init__() missing 1 required keyword-only argument: 'pattern'

pickle can handle mandatory keyword args in other classes derived from object; it's only classes derived from Exception that have issues.

----------
components: Library (Lib)
messages: 371057
nosy: a.badger
priority: normal
severity: normal
status: open
title: pickling exceptions with mandatory keyword args will traceback
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40917>
_______________________________________


More information about the New-bugs-announce mailing list