Skip to content

Commit

Permalink
Count overloaded functions signatures correctly in error message (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwbarton authored and gvanrossum committed Apr 19, 2016
1 parent 33559c0 commit 49e3864
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
sig1 = self.function_type(item.func)
sig2 = self.function_type(item2.func)
if is_unsafe_overlapping_signatures(sig1, sig2):
self.msg.overloaded_signatures_overlap(i + 1, j + 2,
self.msg.overloaded_signatures_overlap(i + 1, i + j + 2,
item.func)

def is_generator_return_type(self, typ: Type) -> bool:
Expand Down
11 changes: 11 additions & 0 deletions mypy/test/data/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,14 @@ def f(x: Sequence[int]) -> int: pass
# These are considered overlapping despite the bound on T due to runtime type erasure.
[out]
main:4: error: Overloaded function signatures 1 and 2 overlap with incompatible return types

[case testOverlappingOverloadCounting]
from typing import overload
class A: pass
class B(A): pass
@overload
def f(x: int) -> None: pass
@overload
def f(x: B) -> str: pass # E: Overloaded function signatures 2 and 3 overlap with incompatible return types
@overload
def f(x: A) -> int: pass

0 comments on commit 49e3864

Please sign in to comment.