[Python-Dev] enum discussion: can someone please summarize open issues?

Guido van Rossum guido at python.org
Mon Apr 29 19:38:46 CEST 2013


On Mon, Apr 29, 2013 at 9:47 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

> At this point I think the best course is to not allow duplicates directly in
> the enum definition, but allow them after the fact:
>
> --> class Color(Enum):
> ...     red = 1
> ...     green = 2
> ...     blue = 3
>
> --> Color.grene = Color.green  # stupid legacy typo
>
> This gives us both some protection against accidental duplicates, while
> still allowing them when necessary; also, no confusion about which is the
> canonical name.

No. Poking a class has a code smell. It should be possible to define
the aliases inside the enum class definition. The canonical one is the
first one in definition order.

--
--Guido van Rossum (python.org/~guido)


More information about the Python-Dev mailing list