A Hacky way of getting a custom Enum
to report the correct type for it value
property
#4883
rayansostenes
started this conversation in
Show and tell
Replies: 1 comment 1 reply
-
The My recommendation is to avoid using the more esoteric features of Here's a simpler solution that is much more straightforward. class ChoiceEnum(enum.Enum):
A = "A"
B = "B"
C = "C"
@property
def label(self):
labelMap = {
"A": "My A choice",
"B": "My B choice",
"C": "My C choice",
}
return labelMap[self.value]
print(ChoiceEnum.A.label) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
What would be a better way to type this without relying on the pyright inference? Is that even possible?
Beta Was this translation helpful? Give feedback.
All reactions