How do I get static code analysis type support for enums (not just runtime support)?

In my experience, python’s enums are pretty bad with typing. For example, pylance doesn’t respect the return type of _generate_next_value_ (however, mypy does).

Such cases require some work which I’d love to do if I knew a bit more details. If any core dev is reading it and wants to assist a little bit – I would greatly appreciate it!

I checked: both mypy (v0.971) and pylance (v2022.7.40) on python 3.11.0b4 do not give any errors even in strict mode for the following code:

from enum import Enum

class A(int, Enum):
    a = "such_string"
    b = 1

class B(str, Enum):
    a = "such_string"
    b = 1

1 Like