[New-bugs-announce] [issue27877] Add recipe for "valueless" Enums to docs

John Hagen report at bugs.python.org
Sat Aug 27 09:42:09 EDT 2016


New submission from John Hagen:

Many programming languages allow the developer to define a enum without specifying values when there would be no significance to those values.  Adding some kind of support in the stdlib itself was rejected due to the high degree of magic that would be needed: https://bugs.python.org/issue26988

I propose that a simple example be added to the enum docs that show a developer how to use a normal Python Enum to create this most common and basic enum (without values).

import enum

class Color(enum.Enum):
    red = object()
    green = object()
    blue = object()

object() returns a new unique value while conveying that that value should not be expected to be used in any meaningful way (unlike an integer value, which could be used to encode the Enum in some way).

There is no extra magic going on here, no new code that needs to be added to the stdlib, and no bare identifiers that could confuse linters.  For example, PyCharm already fully understands the above example and statically types it.

This example also allows the developer to omit the extra @enum.unique() boilerplate that is normally needed, since he or she cannot accidentally use the same integer value twice.

----------
assignee: docs at python
components: Documentation
messages: 273780
nosy: John Hagen, barry, docs at python, eli.bendersky, ethan.furman
priority: normal
severity: normal
status: open
title: Add recipe for "valueless" Enums to docs
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue27877>
_______________________________________


More information about the New-bugs-announce mailing list