[Python-Dev] doctest and pickle

Ethan Furman ethan at stoneleaf.us
Fri Jun 7 18:06:15 CEST 2013


Is there a doctest mailing list?  I couldn't find it.


I'm try to use doctest to verify my docs (imagine that!) but I'm having trouble with the one that uses pickle (imagine 
that!).

Any advice on how to make it work?

Here's the excerpt:

===============================================================================
Pickling
--------

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

The usual restrictions for pickling apply: picklable enums must be defined in
the top level of a module, since unpickling requires them to be importable
from that module.
===============================================================================

Oh, and I just realized this is probably why the flufl.enum docs import from a preexisting module instead of creating a 
new class on the spot.  Still, it would be nice if this could work.

Any ideas?

--
~Ethan~


More information about the Python-Dev mailing list