You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I override __eq__ and return a custom type, the MyPy checks succeed when my custom type is on the LHS of the equality, but fail when my custom type is on the RHS of the equality.
Here is an example to illustrate: line 14 yields no error but line 16 yields an error:
Incompatible types in assignment (expression has type "bool", variable has type "MyClass")
from typing import Any
class MyClass:
def __eq__(self, other: Any) -> 'MyClass':
return self
def test_tmp() -> None:
x = MyClass()
y = 1.
result: MyClass
result = (x == y)
assert type(result) == MyClass
result = (y == x)
assert type(result) == MyClass
The test passes, i.e. I get back an object of type MyClass when x is on the LHS or RHS of my equality.
NB - there is also a MyPy error on line 6, Return type of "__eq__" incompatible with supertype "object" - this is because of #2783. I think my issue is separate from this one.
Version numbers: Python 3.6.5, mypy 0.641.
The text was updated successfully, but these errors were encountered:
main.py:6: error: Return type "MyClass" of "__eq__" incompatible with return type "bool" in supertype "object" [override]
main.py:16: error: Incompatible types in assignment (expression has type "bool", variable has type "MyClass") [assignment]
Found 2 errors in 1 file (checked 1 source file)
When I override
__eq__
and return a custom type, the MyPy checks succeed when my custom type is on the LHS of the equality, but fail when my custom type is on the RHS of the equality.Here is an example to illustrate: line 14 yields no error but line 16 yields an error:
The test passes, i.e. I get back an object of type
MyClass
whenx
is on the LHS or RHS of my equality.NB - there is also a MyPy error on line 6,
Return type of "__eq__" incompatible with supertype "object"
- this is because of #2783. I think my issue is separate from this one.Version numbers: Python 3.6.5, mypy 0.641.
The text was updated successfully, but these errors were encountered: