How do enums work with mypy? Should fields which a...
# development
a
How do enums work with mypy? Should fields which are enum values just be `str`s? Or is there some magic?
h
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