python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.33k stars 2.81k forks source link

More specific overlapping overload errors #3819

Open OddBloke opened 7 years ago

OddBloke commented 7 years ago

Again when wrapping my head around #3805, I was thrown off by the output of mypy against:

from typing import *

@overload
def f(arg: str = "foo") -> AbstractSet[Tuple[str, str]]: ...

@overload
def f(arg: int = 0) -> AbstractSet[Tuple[str, Tuple[str, int]]]: ...

which gives

test.pyi:4: error: Overloaded function signatures 1 and 2 overlap with incompatible return types

The problem here is that each overload can be called without arguments (but I didn't see this until an eagle-eyed BDFL pointed it out :grin:).

It would be good if the error message could include a little more information about the ways in which the signatures overlap, to make fixing the error an easier experience.

JukkaL commented 7 years ago

It would be nice if would generate a bit more useful error message for at least the most common cases of incompatible overload items.