On 10/19/2019 11:25 PM, Andrew Barnert via Python-ideas wrote:
On Oct 19, 2019, at 22:57, Steve Jorgensen wrote:
The idea is to use a class as a singleton collection of choices where every choice appears both as an attribute of the class/singleton and as a value/label pair when treating it as a sequence.
What you’re looking for is a way to auto-assign attributes on lookup during class definition. Which is an idea that was actually brought up for enums, and specifically rejected in PEP 435, but there’s a proof of concept implementation of it anyway if you want it.
It is actually implemented in the `aenum`* library. The code in question is in _EnumDict, and my workaround for the problem was another variable (IIRC, _ignore_) that listed any names that were outside the Enum's scope. -- ~Ethan~ * disclosure: I'm the one to hold responsible for the stdlib enum, enum34, and aenum.