Skip to content
Snippets Groups Projects
Commit cefd33ab authored by Michael Kuron's avatar Michael Kuron 🎓
Browse files

Fix deepcopying on Python 3.11

Tested with Python 3.10 and 3.11 and Sympy 1.9 and 1.11
parent e356d3d7
1 merge request!329Fix deepcopying on Python 3.11
Pipeline #53316 failed with stages
in 4 minutes and 9 seconds
...@@ -187,18 +187,15 @@ def get_type_of_expression(expr, ...@@ -187,18 +187,15 @@ def get_type_of_expression(expr,
# Fix for sympy versions from 1.9 # Fix for sympy versions from 1.9
sympy_version = sp.__version__.split('.') sympy_version = sp.__version__.split('.')
if int(sympy_version[0]) * 100 + int(sympy_version[1]) >= 109: sympy_version_int = int(sympy_version[0]) * 100 + int(sympy_version[1])
if sympy_version_int >= 109:
# __setstate__ would bypass the contructor, so we remove it # __setstate__ would bypass the contructor, so we remove it
sp.Number.__getstate__ = sp.Basic.__getstate__ if sympy_version_int >= 111:
del sp.Basic.__getstate__ del sp.Basic.__setstate__
del sp.Symbol.__setstate__
class FunctorWithStoredKwargs: else:
def __init__(self, func, **kwargs): sp.Number.__getstate__ = sp.Basic.__getstate__
self.func = func del sp.Basic.__getstate__
self.kwargs = kwargs
def __call__(self, *args):
return self.func(*args, **self.kwargs)
# __reduce_ex__ would strip kwargs, so we override it # __reduce_ex__ would strip kwargs, so we override it
def basic_reduce_ex(self, protocol): def basic_reduce_ex(self, protocol):
...@@ -210,9 +207,7 @@ if int(sympy_version[0]) * 100 + int(sympy_version[1]) >= 109: ...@@ -210,9 +207,7 @@ if int(sympy_version[0]) * 100 + int(sympy_version[1]) >= 109:
state = self.__getstate__() state = self.__getstate__()
else: else:
state = None state = None
return FunctorWithStoredKwargs(type(self), **kwargs), args, state return partial(type(self), **kwargs), args, state
sp.Number.__reduce_ex__ = sp.Basic.__reduce_ex__
sp.Basic.__reduce_ex__ = basic_reduce_ex sp.Basic.__reduce_ex__ = basic_reduce_ex
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment