Message273780
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. |
|
Date |
User |
Action |
Args |
2016-08-27 13:42:09 | John Hagen | set | recipients:
+ John Hagen, barry, eli.bendersky, docs@python, ethan.furman |
2016-08-27 13:42:09 | John Hagen | set | messageid: <1472305329.28.0.714722611618.issue27877@psf.upfronthosting.co.za> |
2016-08-27 13:42:09 | John Hagen | link | issue27877 messages |
2016-08-27 13:42:08 | John Hagen | create | |
|