Skip to content

Instantly share code, notes, and snippets.

@Tinche
Last active September 8, 2016 12:51
Show Gist options
  • Save Tinche/33b702c6a1c3e4093be95953720cd80c to your computer and use it in GitHub Desktop.
Save Tinche/33b702c6a1c3e4093be95953720cd80c to your computer and use it in GitHub Desktop.
import attr
import pickle
@attr.s(frozen=True)
class A(object):
x = attr.ib()
@attr.s(slots=True)
class B(object):
x = attr.ib()
@attr.s(slots=True, frozen=True)
class C(object):
x = attr.ib()
try:
pickle.loads(pickle.dumps(A(1)))
except:
print("A failed.")
else:
print("A succeeded.")
try:
pickle.loads(pickle.dumps(B(1)))
except:
print("B failed.")
else:
print("B succeeded.")
try:
pickle.loads(pickle.dumps(C(1)))
except:
print("C failed.")
else:
print("C succeeded.")
> python p.py
A succeeded.
B succeeded.
C failed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment