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@python
components: Documentation
messages: 273780
nosy: John Hagen, barry, docs@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 <[email protected]>
<https://bugs.python.org/issue27877>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com