Mypy dislikes bound TypeVar in Enum intermediate subclass
Mypy fails to recognise that values on an Enum class that do not appear at run-time should not count as "existing members".
If T
is moved out of the class definition in the following example, there is no error:
from enum import Enum
from typing import TYPE_CHECKING, TypeVar
class IntermediateEnumBase(Enum):
if TYPE_CHECKING:
T = TypeVar("T", bound="IntermediateEnumBase")
@classmethod
def _missing_(self: type[T], key: Any) -> T: ...
class FinalEnum(IntermediateEnumBase): ... # error: Cannot extend enum with existing members: "IntermediateEnumBase"
...
This is affecting behave_utils.behave.PatternEnum