https://pantsbuild.org/ logo
#development
Title
# development
a

average-vr-56795

04/21/2020, 7:22 PM
How do enums work with mypy? Should fields which are enum values just be `str`s? Or is there some magic?
h

hundreds-father-404

04/21/2020, 7:27 PM
It’s not wonderful. MyPy doesn’t assume that
MyEnum.OPTION1.value
is a
str
because it could be anything. This is a valid enum:
Copy code
class Example(Enum):
  O1 = 1
  O2 = 2
This is also valid:
Copy code
class Example(Enum):
  O1 = "o1"
  O2 = "o2"
I think John has been overriding
__new__
to get MyPy to be happy. He’s done it in a couple recent PRs. I think
ranked_value.py
is the most recent example. Maybe
PexDebugLevel
(something like this) too