Message273145
One solution similar to one proposed by Vedran works with the current Enum:
class Color(Enum):
red = object()
green = object()
blue= object()
I tested this in PyCharm and it is perfectly happy with the autocomplete and everything. The main disadvantage is the boilerplate, of course. And perhaps "object()" does not show the clearest intent, but it depends on your perspective. The repr also looks kind of funny:
>>> repr(Color.red)
<Color.red: <object object at 0x7fb2f353a0d0>>
One possibility would be to add an auto() function to enum as a wrapper around object(), providing a more explicit name and a cleaner repr:
from enum import Enum, auto
class Color(Enum):
red = auto()
blue = auto()
green = auto()
repr(Color.red)
<Color.red>
# auto() means it has no (meaningful) value, so show nothing |
|
Date |
User |
Action |
Args |
2016-08-19 17:11:36 | David Hagen | set | recipients:
+ David Hagen, barry, rhettinger, vstinner, eli.bendersky, ethan.furman, python-dev, veky, abarry, John Hagen, kennethreitz |
2016-08-19 17:11:36 | David Hagen | set | messageid: <1471626696.28.0.447855244538.issue26988@psf.upfronthosting.co.za> |
2016-08-19 17:11:36 | David Hagen | link | issue26988 messages |
2016-08-19 17:11:35 | David Hagen | create | |
|