[Python-ideas] another enum implementation
Ethan Furman
ethan at stoneleaf.us
Wed Feb 13 08:01:30 CET 2013
On 02/12/2013 09:24 PM, Yury Selivanov wrote:
> I'm not sure why, but I didn't see anyone making a point about
> documentation. To me, it's important that stdlib's and other
> libraries' enums are well documented, and I think that the best
> way of providing and enforcing this is to mimic "property" builtin.
>
> class Color(enum.Sequence):
> "Some general docs about Color enum"
> BLACK = enum.value(doc='Black Color')
>
> or
>
> class Color(enum.Flag):
> "..."
> BLACK = enum(doc='Black Color')
> WHITE = enum()
>
> Maybe this is uglier than magic of just writing flags' names,
> but this implementation is much simpler, backwards compatible with
> python 2, and verbose. The latter point is both good and bad, but
> we don't write enums that often to make a bit of verbosity unacceptable.
>
> Just my two cents.
You definitely have a good point about documentation, and I'm going to
add the functionality that Tim has in his which will allow other
attributes on enum values (the difference with his is that mine are
actual instances of their class so all values of one class will have the
same attributes).
However, for small enums, well chosen names should be documentation
enough, so doc strings will not be required. Even more importantly, if
I'm just trying something out I do not want to be forced to add stuff I
don't need.
--
~Ethan~
More information about the Python-ideas
mailing list