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.
//arry/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com