This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author John Hagen
Recipients John Hagen, barry, docs@python, eli.bendersky, ethan.furman
Date 2016-08-27.13:42:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1472305329.28.0.714722611618.issue27877@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-08-27 13:42:09John Hagensetrecipients: + John Hagen, barry, eli.bendersky, docs@python, ethan.furman
2016-08-27 13:42:09John Hagensetmessageid: <1472305329.28.0.714722611618.issue27877@psf.upfronthosting.co.za>
2016-08-27 13:42:09John Hagenlinkissue27877 messages
2016-08-27 13:42:08John Hagencreate