[Python-Dev] Best practices for Enum

Eli Bendersky eliben at gmail.com
Mon May 13 05:26:39 CEST 2013

Thanks for the insights, Raymond. I don't think anyone is planning on
rushing anything. We still have to get the enum module itself committed and
a serious review process has just started for that, so it will take time.

There's no general "let's replace all constants with enums" TODO item that
I know of. It's my hope that such changes will happen very gradually and
only when deemed important and useful by core developers. So it's not
different from any other changes made in the Python repository, really.
Issues will be opened, discussed, code will be reviewed by whomever is
willing to participate.

IIRC Guido wanted to have a printable representation for the socket module
constants like socket.AF_* and socket.SOCK_* because that would be useful
in developing Tulip. Implementing those with IntEnum may be a relatively
non-controversial first foray into actually putting enums to use. But
again, at least as far as I'm concerned there's no concrete todo list at
this point.


On Sun, May 12, 2013 at 4:49 PM, Raymond Hettinger <
raymond.hettinger at gmail.com> wrote:

> After the long design effort for the enum module,
> I'm sure there will be a forthcoming effort to apply
> them pervasively throughout the standard library.
> I would like to ask for a little restraint and for there to
> be individual cost/benefit evaluations for each case.
> On the plus-side, the new integer-enums have a better
> repr than plain integers.
> For internal constants such as those in idlelib and regex,
> the user won't see any benefit at all.  But there will be
> a cost in terms of code churn, risk of introducing errors
> in stable code, modestly slowing-down the code, making
> it more difficult to apply bug fixes across multiple versions
> of Python, and increased code verbosity (i.e. changing
> "if direction=LEFT: ..."  to "if direction is Direction.LEFT: ...")
> For external constants, some thought needs to be given to:
> * is the current API working just fine (i.e. decimal's ROUND_DOWN)
> * will enums break doctests or any existing user code
> * will it complicate users converting from Python 2
> * do users now have to learn an additional concept
> * does it complicate the module in any way
> I'm hoping that enums get used only in cases where they
> clearly improve the public API (i.e. cases such as sockets
> that have a large number of integer constants) rather
> than having a frenzy of every constant, everywhere getting
> turned into an enum.
> I would like to see enums used as tool for managing complexity,
> rather than becoming a cause of added complexity by being used
> for every problem, the tall and small, even where it is not needed at all.
> my-two-cents-ly yours,
> Raymond
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/python-dev/eliben%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20130512/2815db7d/attachment.html>

More information about the Python-Dev mailing list