[Python-Dev] PEP 435: pickling enums created with the functional API

Larry Hastings larry at hastings.org
Wed May 8 00:36:06 CEST 2013

On 05/07/2013 08:47 AM, Eli Bendersky wrote:
>     def Color = Enum('red green blue')
> It's an interesting idea, but as NIck suggested we should probably 
> discuss it on the python-ideas list. [...]
> A special syntax raises more questions though, because it has to be 
> defined very precisely. Feel free to come up with a complete proposal 
> to python-ideas, defining the interesting semantics.

We don't need a special syntax, we can already do this:

@Enum('red green blue')
def Color(): pass

Here, Enum would take the one argument, and return a function working as 
a function decorator.  That decorator would ignore the body of the 
function and return the Enum.  It's awful, but then so is the idea of 
creating special syntax just for the functional form of Enum--if we're 
willing to go down that road, let's just add new syntax for enums and be 
done with it.

As for the non-pickleability of enums created with the functional 
interface, why can't it use the same mechanism (whatever it is) as the 
three-argument form of type?  Types created that way are dynamic, yet 
have a __module__ and are pickleable.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130507/97a3ad8c/attachment.html>

More information about the Python-Dev mailing list