Skip to content

Commit 49e3864

Browse files
rwbartongvanrossum
authored andcommitted
Count overloaded functions signatures correctly in error message (#1407)
1 parent 33559c0 commit 49e3864

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
498498
sig1 = self.function_type(item.func)
499499
sig2 = self.function_type(item2.func)
500500
if is_unsafe_overlapping_signatures(sig1, sig2):
501-
self.msg.overloaded_signatures_overlap(i + 1, j + 2,
501+
self.msg.overloaded_signatures_overlap(i + 1, i + j + 2,
502502
item.func)
503503

504504
def is_generator_return_type(self, typ: Type) -> bool:

mypy/test/data/check-overloading.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,3 +630,14 @@ def f(x: Sequence[int]) -> int: pass
630630
# These are considered overlapping despite the bound on T due to runtime type erasure.
631631
[out]
632632
main:4: error: Overloaded function signatures 1 and 2 overlap with incompatible return types
633+
634+
[case testOverlappingOverloadCounting]
635+
from typing import overload
636+
class A: pass
637+
class B(A): pass
638+
@overload
639+
def f(x: int) -> None: pass
640+
@overload
641+
def f(x: B) -> str: pass # E: Overloaded function signatures 2 and 3 overlap with incompatible return types
642+
@overload
643+
def f(x: A) -> int: pass

0 commit comments

Comments
 (0)