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
Improve error message for overload overrides w/ swapped variants (#5369)
This commit is intended to resolve#1270.
Currently, running mypy on the following program:
from typing import overload
class Parent:
@overload
def foo(self, x: A) -> A: ...
@overload
def foo(self, x: B) -> B: ...
class Child(Parent):
@overload
def foo(self, x: B) -> B: ...
@overload
def foo(self, x: A) -> A: ...
...will make mypy report the following error -- it considers the fact
that we've swapped the order of the two variants to be unsafe:
test.pyi:10: error: Signature of "foo" incompatible with supertype "Parent"
This error message can be confusing for some users who may not be
aware that the order in which your overloads are defined can sometimes
matter/is something mypy relies on.
This commit modifies the error message to the following to try
and make this more clear:
test.pyi:10: error: Signature of "foo" incompatible with supertype "Parent"
test.pyi:10: note: Overload variants must be defined in the same order as they are in "Parent"
0 commit comments