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

Dill gives incorrect, invalid name to nested namedtuples in 3.7 #288

Closed
sjchilcote opened this issue Nov 12, 2018 · 0 comments · Fixed by #448
Closed

Dill gives incorrect, invalid name to nested namedtuples in 3.7 #288

sjchilcote opened this issue Nov 12, 2018 · 0 comments · Fixed by #448
Labels
Milestone

Comments

@sjchilcote
Copy link

sjchilcote commented Nov 12, 2018

This (reduced from real-world code) example fails:

import collections, dill

class A:
    class B(collections.namedtuple("B", ["one", "two"])):
        pass

a = A()
aa = dill.loads(dill.dumps(a))

Dill thinks B is named A.B, which is not a valid name for a NamedTuple since it has to be a valid identifier, and Python gives ValueError: Type names and field names must be valid identifiers: 'A.B'

Adding the following makes it work again for me at least, but I don't know whether or not the name being wrong should be considered a deeper issue.

In _dill._create_namedtuple:

import collections
name = name.split('.')[-1] #add this line - removes the parent's name, 'A.B' -> 'B'
t = collections.namedtuple(name, fieldnames)
anivegesana added a commit to anivegesana/dill that referenced this issue Jan 5, 2022
anivegesana added a commit to anivegesana/dill that referenced this issue Jan 25, 2022
anivegesana added a commit to anivegesana/dill that referenced this issue Jan 25, 2022
anivegesana added a commit to anivegesana/dill that referenced this issue Jan 25, 2022
anivegesana added a commit to anivegesana/dill that referenced this issue Jan 27, 2022
mmckerns pushed a commit that referenced this issue Apr 21, 2022
* fix #288 nested namedtuples

* Remove special case for PyPy 2.7 that doesn't exist

__kwdefaults__ and __annotations__ are invalid in PyPy2.7

* Bug fix for __qualname__ on classes

* Fix bug if _postproc not present and use _setitems
@mmckerns mmckerns added this to the dill-0.3.5 milestone Apr 22, 2022
@mmckerns mmckerns added the bug label May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants