uqfoundation/dill

dill fails to pickle sympy.Float under Python 3.7 for dill.settings["recurse"]=True

Closed this issue · 1 comments

Under python 3.7, dill fails to pickle sympy.Float objects when the "recurse" setting is set to True:

Python 3.7.13 (default, Mar 28 2022, 08:03:21) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import sympy
>>> dill.__version__
'0.3.5.1'
>>> sympy.__version__
'1.10.1'
>>> tst = sympy.Float(3.3)
>>> dill.copy(tst)
3.30000000000000
>>> dill.settings['recurse'] = True
>>> dill.copy(tst)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\drjen\miniconda3\envs\py37\lib\site-packages\dill\_dill.py", line 324, in copy
    return loads(dumps(obj, *args, **kwds), ignore=ignore)
.
.
.
 File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 368, in _disassemble_recursive
    _disassemble_recursive(x, file=file, depth=depth)
  File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 360, in _disassemble_recursive
    disassemble(co, file=file)
  File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 357, in disassemble
    co.co_consts, cell_names, linestarts, file=file)
  File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 390, in _disassemble_bytes
    line_offset=line_offset):
  File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 311, in _get_instructions_bytes
    labels = findlabels(code)
  File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 424, in findlabels
    for offset, op, arg in _unpack_opargs(code):
  File "C:\Users\drjen\miniconda3\envs\py37\lib\dis.py", line 408, in _unpack_opargs
    for i in range(0, len(code), 2):
RecursionError: maximum recursion depth exceeded in comparison

The error disappears for Python >=3.8, and also does not occur in the absence of the "recurse" setting. Unfortunately I need to support Python 3.7 and am forced to use the "recurse" mode.

Thanks for reporting.
Original reference: https://stackoverflow.com/questions/73321138

Python 3.7.13 (default, May 10 2022, 11:13:40) 
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dill
>>> import sympy
>>> dill.__version__
'0.3.6.dev0'
>>> sympy.__version__
'1.10.1'
>>> tst = sympy.Float(3.3)
>>> dill.copy(tst)
3.30000000000000
>>> dill.settings['recurse'] = True
>>> dill.copy(tst)
3.30000000000000
>>> dill.detect.errors(tst)
>>> 

I believe this is a duplicate issue (of #477 ?)... and if you update to dill master, this should work for you. I'm going to mark it as duplicate and close it, but please reopen it if the update doesn't solve the issue for you.