I would like to have an Enum with internal property for each enum value, this property can't be set or initialized by the user, but once the user has created Enum from a value, he would be able to read (get) this internal property based on the value.
e.g.
class Channels(Enum): Email = 1, True # True is the value of the internal property for value 1 Sms = 2, True # True is the value of the internal property for value 2 Log = 3, False # False is the value of the internal property for value 3 Problem is that currently in order to create an instance of this class I need to: x = Channels((1, True)) and that's bad. I want to be able to still create instances like: x = Channels(1) (i.e. True is the internal property of 1, it shouldn't be specified by the user).
My second try was:
class Channels2(Enum): @DynamicClassAttribute def internal_property(self): if self.value == 1: return True elif self.value == 2: return True elif self.value == 3: return False Email = 1 Sms = 2 Log = 3 And this seems to be working (x = Channels(1) is working and x.internal_property returns True, as it should).
The problem here is that it feels not so efficient, executing those if statements every time the internal_property is accessed.. Is there any other way making the Enum treat internal_property as a an extra field of the instance (on top of Enum regular name and value fields)?