[Python-Dev] doctest and pickle (original) (raw)

Stephen J. Turnbull stephen at xemacs.org
Sat Jun 8 07🔞15 CEST 2013


Ethan Furman writes:

Enumerations can be pickled and unpickled::

 >>> from enum import Enum
 >>> class Fruit(Enum):
 ...     tomato = 1
 ...     banana = 2
 ...     cherry = 3
 ...
 >>> from pickle import dumps, loads
 >>> Fruit.tomato is loads(dumps(Fruit.tomato))
 True

[...] Still, it would be nice if this could work.

Well, you could cheat and reverse the test. ;-)

I assume the problem is that loads proceeds to recreate the Fruit enum, rather than checking if there already is one? Maybe the metaclass can check somehow? At the very least, if this can't work in this implementation, unpickling should be an error.



More information about the Python-Dev mailing list