Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

badly named namedtuple fails in python 3.5 and 3.6 #132

Closed
mmckerns opened this issue Oct 5, 2015 · 2 comments
Closed

badly named namedtuple fails in python 3.5 and 3.6 #132

mmckerns opened this issue Oct 5, 2015 · 2 comments
Labels
Milestone

Comments

@mmckerns
Copy link
Member

mmckerns commented Oct 5, 2015

For python3.5 one test fails in test_classdef.py:

>>> 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
>>> 
@mmckerns mmckerns added the bug label Oct 5, 2015
@mmckerns mmckerns changed the title badly named namedtuple fails in python3.5 badly named namedtuple fails in python 3.5 and 3.6 Dec 28, 2016
@mmckerns
Copy link
Member Author

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.

@mmckerns
Copy link
Member Author

see #72

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant