[Python-ideas] adopt an enum type for the standard library?
Jonathan Marshall
junk at themilkyway.com
Thu Jan 24 11:03:18 CET 2008
Christian Heimes wrote:
> Mark Summerfield wrote:
>
>> There is an enum module in PyPI
>> http://pypi.python.org/pypi/enum/
>> and there are several versions in the Python Cookbook.
>>
>> Wouldn't one of these be worth adopting for the standard library?
>>
>
>
> It might be worth adding an enum to Python 2.6. I'm +0 on it.
>
> The enum implementation from pypi is not sufficient for Python core. I
> don't like its __cmp__ and __hash__ code. I also miss the feature to set
> a start value or to skip values:
>
>
I'd be +1 on adding an enum type. I chose an enum type from the cookbook
for our company to use. All was great until 1-2 years later when we
needed to start persisting objects that contained enums. We found that
that publically available enums wouldn't cope and we had to invest
signficant effort in changing our code. E.g. the enum type from pypi:
>>> from enum import Enum
>>> import pickle
>>>
>>> Colours = Enum('red', 'blue', 'green')
>>> x = pickle.dumps(Colours.red)
>>> y = pickle.loads(x)
>>> print y
red
>>> assert y == Colours.red
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError
Also, we find that experienced python programmers are use to the absence
of a standard enum type but new python programmers are surprised by its
absence - it's not 'batteries included'.
So I think there would be value in adding an enum to the standard
library that does the job correctly.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080124/332cbbd9/attachment.html>
More information about the Python-ideas
mailing list