enums_member_values
error
Enum member value incompatible with _value_ type annotation
When an enum class declares _value_: T (annotation-only, no value), all member values assigned in the class body must be compatible with T. Additionally, if self._value_ = param appears in __init__, the parameter's type annotation must be compatible with the declared _value_: T.
from enum import Enum
class Color(Enum):
_value_: int
RED = 1 # OK — int matches int
GREEN = "green" # E — str is not compatible with int
class Planet(Enum):
_value_: str
def __init__(self, value: int, mass: float, radius: float):
self._value_ = value # E — int is not compatible with str
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
enums_member_values down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/enums_member_values