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
>>> from collections import namedtuple
>>> Z = namedtuple("Z", ['a','b'])
>>> Zi = Z(0,1)
>>> X = namedtuple("Y", ['a','b'])
>>> X.__name__ = "X"
>>> Xi = X(0,1)
>>> import dill
>>> assert Z == dill.copy(Z)
>>> assert Zi == dill.copy(Zi)
>>> dill.detect.errors(X)
PicklingError("Can't pickle <class '__main__.Y'>: it's not found as __main__.Y",)
>>> dill.detect.trace(True)
>>> assert X == dill.copy(X)
T6: <class '__main__.Y'>
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pickle.py", line 268, in _getattribute
obj = getattr(obj, subpath)
AttributeError: module '__main__' has no attribute 'Y'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pickle.py", line 907, in save_global
obj2, parent = _getattribute(module, name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pickle.py", line 271, in _getattribute
.format(name, obj))
AttributeError: Can't get attribute 'Y' on <module '__main__' (<_frozen_importlib_external.SourceFileLoader object at 0x10b3910b8>)>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mmckerns/lib/python3.5/site-packages/dill-0.2.5.dev0-py3.5.egg/dill/dill.py", line 161, in copy
return loads(dumps(obj, *args, **kwds))
File "/Users/mmckerns/lib/python3.5/site-packages/dill-0.2.5.dev0-py3.5.egg/dill/dill.py", line 197, in dumps
dump(obj, file, protocol, byref, fmode, recurse)#, strictio)
File "/Users/mmckerns/lib/python3.5/site-packages/dill-0.2.5.dev0-py3.5.egg/dill/dill.py", line 190, in dump
pik.dump(obj)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pickle.py", line 408, in dump
self.save(obj)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pickle.py", line 475, in save
f(self, obj) # Call unbound method with explicit self
File "/Users/mmckerns/lib/python3.5/site-packages/dill-0.2.5.dev0-py3.5.egg/dill/dill.py", line 1133, in save_type
StockPickler.save_global(pickler, obj)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/pickle.py", line 911, in save_global
(obj, module_name, name))
_pickle.PicklingError: Can't pickle <class '__main__.Y'>: it's not found as __main__.Y
>>> X.__name__ = "Y"
>>> Y = X
>>> assert Y == dill.copy(Y)
T6: <class '__main__.Y'>
# T6
>>>
The text was updated successfully, but these errors were encountered:
Ok, so this particular test case has been fixed by using __qualname__ instead of __name__ for python 3.5+ (i.e. the below):
X = namedtuple("Y", ['a','b'])
if hex(sys.hexversion) >= '0x30500f0':
X.__qualname__ = "X" #XXX: name must 'match' or fails to pickle
else:
X.__name__ = "X"
Xi = X(0,1)
There's still the issue that a badly named namedtuple fails to serialize... but I think that's not the point of this issue.
For
python3.5
one test fails intest_classdef.py
:The text was updated successfully, but these errors were encountered: