Код: Выделить всё
class Foo:
def __init__(self, key :str) -> None:
self.key = key
def __eq__(self, other :Foo) -> bool:
return self.key == other.key
print('should be true: ', Foo('abc') == Foo('abc'))
print('should be false: ', Foo('abc') == Foo('def'))
Код: Выделить всё
Traceback (most recent call last):
File "class_own_type.py", line 1, in
class Foo:
File "class_own_type.py", line 5, in Foo
def __eq__(self, other :Foo) -> bool:
NameError: name 'Foo' is not defined
Код: Выделить всё
class_own_type.py:5: error: Argument 1 of "__eq__" incompatible with supertype "object"
Подробнее здесь: https://stackoverflow.com/questions/428 ... definition