mypy error, overload with Union/Optional, “Overloaded function signatures 1 and 2 overlap with incompatible return types”
问题 So, let's start with an example. Suppose we have several types that can be combined together, let's say we are using __add__ to implement this. Unfortunately, due to circumstances beyond our control, everything has to be "nullable", so we are forced to use Optional everywhere. from typing import Optional, List, overload class Foo: value: int def __init__(self, value: int) -> None: self.value = value def __add__(self, other: 'Foo') -> 'Optional[Foo]': result = self.value - other.value if