Pointe = namedtuple('Point'...The class exists, there is an existing valid reference to it, and Python itself knows about it and the class itself knows its own name and namedtuple generates the right __getnewargs__. Everything is there for this to "just work" but pickle expects that every class object will have a reference to it of the same name which is kinda weird when you think about it.
You can see it with this stupid little program.
from collections import namedtuple
import pickle
def get_all_subclasses(cls):
all_subclasses = []
for subclass in cls.__subclasses__():
if subclass != type:
all_subclasses.append(subclass)
all_subclasses.extend(get_all_subclasses(subclass))
return all_subclasses
E = namedtuple('EEEEEEEEEEEEEEEEEEE', 'x')
e = E(x='hello')
for cls in get_all_subclasses(object):
print(cls)
pickle.dumps(e)
You'll that the class it there and called the right thing! But pickle tries to look up a reference to it under __main__.Yeah: its qualname. The qualname, as per PEP 3155, is defined as:
> a dotted path leading to the object from the module top-level
so of course pickle can't cope with this information being incorrect. (How would you make it work?)
This is the part that, to me, is really odd because pickle knows (in theory) the class and module name of the thing it needs to instantiate and the class objects themselves know their name and module.
Up to the lack efficiency actually doing this you could just enumerate all class objects to find the one with the right name and module name.
You get nested classes for free this way and you break the requirement that there be references to class objects of the same name in the module.