Skip to content

Commit

Permalink
Merge pull request #23259 from oscarbenjamin/pr_unpickling_unyt_110
Browse files Browse the repository at this point in the history
fix: add __setstate__ to support old pickles
  • Loading branch information
oscarbenjamin committed Mar 19, 2022
2 parents 0a66d06 + ec5a994 commit 77f1d79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sympy/core/basic.py
Expand Up @@ -135,6 +135,10 @@ def __getnewargs__(self):
def __getstate__(self):
return None

def __setstate__(self, state):
for name, value in state.items():
setattr(self, name, value)

def __reduce_ex__(self, protocol):
if protocol < 2:
msg = "Only pickle protocol 2 or higher is supported by SymPy"
Expand Down
11 changes: 11 additions & 0 deletions sympy/utilities/tests/test_pickling.py
Expand Up @@ -701,3 +701,14 @@ def test_deprecation_warning():

def test_issue_18438():
assert pickle.loads(pickle.dumps(S.Half)) == 1/2


#================= old pickles =================
def test_unpickle_from_older_versions():
data = (
b'\x80\x04\x95^\x00\x00\x00\x00\x00\x00\x00\x8c\x10sympy.core.power'
b'\x94\x8c\x03Pow\x94\x93\x94\x8c\x12sympy.core.numbers\x94\x8c'
b'\x07Integer\x94\x93\x94K\x02\x85\x94R\x94}\x94bh\x03\x8c\x04Half'
b'\x94\x93\x94)R\x94}\x94b\x86\x94R\x94}\x94b.'
)
assert pickle.loads(data) == sqrt(2)

0 comments on commit 77f1d79

Please sign in to comment.