-
-
Notifications
You must be signed in to change notification settings - Fork 374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for pickle protocol special methods #139
Comments
Doesn't this work already? See #79 and the related pull request. |
If I remove my class's
(This is open source code, but in a currently unpushed branch.) In any case, the important thing is that I suppose it's also possible that the missing |
Hm, if you could prepare a small test case and give us your Python version, I can take a look. (Yes, attrs never calls super()). |
Yep, thanks. I'll try to craft one up. |
So do we have a executive summary of what’s going on here? :) |
@hynek I am currently unable to produce a boiled down example, so feel free to close this for now. If I can craft a small reproducer I'll submit and reopen. |
Here's a short reproducer that exploits the fact that import attr
import pickle
class B:
def __new__(cls, *args, **kwargs):
retval = object.__new__(cls)
retval.args = args
return retval
def __reduce__(self):
return type(self), self.args
def __repr__(self):
return repr(self.args)
@attr.s
class C(B):
foo = attr.ib()
bar = attr.ib()
b1 = B(1, 2)
b2 = B(foo=1, bar=2)
c1 = C(1, 2)
c2 = C(foo=1, bar=2)
print('attr.__version__', attr.__version__)
print('b1', pickle.loads(pickle.dumps(b1))) # works fine
print('b2', pickle.loads(pickle.dumps(b2))) # works fine
print('c1', pickle.loads(pickle.dumps(c1))) # works fine
print('c2', pickle.loads(pickle.dumps(c2))) # fails Here's the output I see locally:
I hit this when inheriting from |
This should be solved by #642. |
It might be kind of cool for
@attr.s
to optionally support__getstate__()
and__setstate__()
. I'm using the following and it seems to work well:The text was updated successfully, but these errors were encountered: