How to fix the [assignment]
error raised by mypy when an object attribute type is different from its parent?
For instance, consider this Operation
class. mypy complains about replace
being a str
and overloading the type from str.replace.
from enum import StrEnum
class Operation(StrEnum):
add = "add"
replace = "replace"
remove = "remove"
The mypy output:
error: Incompatible types in assignment (expression has type "str", base class "str" defined the type as "Callable[[str, str, str, SupportsIndex], str]") [assignment]
How can I solve this, possibly without renaming the attribute?