Closed
Description
Actual example of this code can be found in Python 3.6's enum with Flag
and IntFlag
.
Minimal repro::
from typing import TypeVar
_T = TypeVar('_T')
class Base:
def __or__(self: _T, other: _T) -> _T: ...
def __and__(self: _T, other: _T) -> _T: ...
def __xor__(self: _T, other: _T) -> _T: ...
class Other(int, Base): # <-- errors here
def __or__(self: _T, other: Union[int, _T]) -> _T: ... # type: ignore
def __and__(self: _T, other: Union[int, _T]) -> _T: ... # type: ignore
def __xor__(self: _T, other: Union[int, _T]) -> _T: ... # type: ignore
Expected behavior: no errors.
Actual behavior:
f:11: error: Definition of "__and__" in base class "int" is incompatible with definition in base class "Base"
f:11: error: Definition of "__or__" in base class "int" is incompatible with definition in base class "Base"
f:11: error: Definition of "__xor__" in base class "int" is incompatible with definition in base class "Base"
The errors would be fine if Other
didn't redefine the methods itself. In this case the incompatibility in base classes is irrelevant.