[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

Ethan Furman ethan at stoneleaf.us
Sat Apr 27 20:24:40 CEST 2013


On 04/27/2013 10:35 AM, Guido van Rossum wrote:

On Sat, Apr 27, 2013 at 10:04 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

While this will certainly work, it means you can't have class variables that happen to be the same type as the enum -- so no int in an IntEnum, for example.

The solution I like best is the helper class (called, originally enough, enum), and only those items get transformed: class Planet(IntEnum): MERCURY = enum(1) VENUS = enum(2) EARTH = enum(3) roughpi = 3 # not transformed If this means that the most plain vanilla enum definition still has to use the enum(i) notation, I'm against it. Why do you want roughpi to be a class variable anyway? The whole point of an enum is that it's not a kitchen sink class. An enum for the planets will need other support code that doesn't live in the enum class -- it shouldn't be considered a general scope for miscellanea. (TBH, I think that using classes to scope variables is mostly misguided anyway -- the standard mechanism for scoping is the module.)

The two primary use cases I see are the (1) quick give me some names to values so I can fiddle and experiment, and the (2) production code with nice docs and the whole shebang.

For (1) I would just use the _make (or whatever it's called) to give me something; for (2) using 'enum()' so that a docstring can also be added (even encouraged ;) seems like a Good Thing.

And no, I have no idea what rough_pi is doing there, besides being an example on an int that doesn't get transformed. ;)

-- Ethan



More information about the Python-Dev mailing list