Open
Description
Just stumbled across an interesting issue. The kw_only
flag seems to break pickling of objects. E.g.:
import attr
import pickle
@attr.s(auto_exc=True, kw_only=False)
class Positional(Exception):
field: int = attr.ib()
@attr.s(slots=False, auto_exc=True, kw_only=True)
class KwOnly(Exception):
field: int = attr.ib()
A = Positional(field=1)
B = KwOnly(field=1)
print('A', pickle.loads(pickle.dumps(A)))
print('B', pickle.loads(pickle.dumps(B)))
raises this error
Traceback (most recent call last):
File "attrs_kwonly.py", line 19, in <module>
print('B', pickle.loads(pickle.dumps(B)))
TypeError: __init__() takes 1 positional argument but 2 were given
I couldn't find any mention in previous issues, or current documentation about this behaviour.