You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm facing the same problem as @pranav9056 in #243.
When the to-be-pickled class is in a file and edited after doing so, dill.loads will return the updated class, despite using the ignore=True option.
The follwoing code is pretty much the same as this SO example from @mmckerns but with a class defined in a file:
>>> import dill
>>> import importlib
>>> import test_file # file with class
>>> f = test_file.Foo()
>>> _f = dill.dumps(f)
*changing class Foo in test_file.py*
>>> importlib.reload(test_file)
<module 'test_file' from 'C:\\test_file.py'>
>>> g = test_file.Foo()
>>> f_ = dill.loads(_f, ignore=True)
>>> f_.bar()
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: bar() missing 1 required positional argument: 'x'
>>> g.bar() # expected behavior
Traceback (most recent call last):
File "<input>", line 1, in <module>
TypeError: bar() missing 1 required positional argument: 'x'
The text was updated successfully, but these errors were encountered:
I have noticed that dumps returns a rather small byte string in this case (b'\x80\x03ctest_file\nFoo\nq\x00)\x81q\x01.');
whereas the SO example returns this: b'\x80\x03cdill._dill\n_create_type\nq\x00(cdill._dill\n_load_type\nq\x01X\x04\x00\x00\x00typeq\x02\x85q\x03Rq\x04X\x03\x00\x00\x00Fooq\x05h\x01X\x06\x00\x00\x00objectq\x06\x85q\x07Rq\x08\x85q\t}q\n(X\n\x00\x00\x00__module__q\x0bX\x08\x00\x00\x00__main__q\x0cX\x03\x00\x00\x00barq\rcdill._dill\n_create_function\nq\x0e(h\x01X\x08\x00\x00\x00CodeTypeq\x0f\x85q\x10Rq\x11(K\x01K\x00K\x01K\x01KCC\x04d\x01S\x00q\x12NK\x05\x86q\x13)X\x04\x00\x00\x00selfq\x14\x85q\x15X\x07\x00\x00\x00<input>q\x16h\rK\x04C\x02\x00\x01q\x17))tq\x18Rq\x19c__builtin__\n__main__\nh\rNN}q\x1atq\x1bRq\x1cX\x07\x00\x00\x00__doc__q\x1dNX\r\x00\x00\x00__slotnames__q\x1e]q\x1futq Rq!)\x81q".'
So, back in 2015, it appeared that there was no intended support for saving a class defined in a module. Has anything specifically changed since then? (It would seem not as the same limitation persists.)
I'm facing the same problem as @pranav9056 in #243.
When the to-be-pickled class is in a file and edited after doing so,
dill.loads
will return the updated class, despite using theignore=True
option.The follwoing code is pretty much the same as this SO example from @mmckerns but with a class defined in a file:
The text was updated successfully, but these errors were encountered: