Skip to content

Commit 5873910

Browse files
committed
Allow partial overlap when checking overload alternatives
1 parent 0b8fed5 commit 5873910

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

mypy/checker.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,12 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
799799

800800
# Is the overload alternative's arguments subtypes of the implementation's?
801801
if not is_callable_compatible(
802-
impl, sig1, is_compat=is_subtype, is_proper_subtype=False, ignore_return=True
802+
impl,
803+
sig1,
804+
is_compat=is_subtype,
805+
allow_partial_overlap=True,
806+
is_proper_subtype=False,
807+
ignore_return=True,
803808
):
804809
self.msg.overloaded_signatures_arg_specific(i + 1, defn.impl)
805810

test-data/unit/check-overloading.test

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5323,7 +5323,6 @@ x = register(Foo)
53235323
reveal_type(x) # N: Revealed type is "builtins.int"
53245324
[builtins fixtures/dict.pyi]
53255325

5326-
53275326
[case testOverloadWithObjectDecorator]
53285327
from typing import Any, Callable, Union, overload
53295328

@@ -6693,3 +6692,24 @@ class B:
66936692
def f(self, *args, **kwargs):
66946693
pass
66956694
[builtins fixtures/tuple.pyi]
6695+
6696+
[case testOverloadKeywordArgsAndKwargs]
6697+
from typing import Optional, overload
6698+
6699+
@overload
6700+
def f(x: int = 0, **kwargs: str) -> None:
6701+
...
6702+
@overload
6703+
def f(x: int = 0, *, y: int, **kwargs: str) -> str:
6704+
...
6705+
def f(x: int = 0, *, y: Optional[int] = None, **kwargs: str) -> Optional[str]:
6706+
...
6707+
6708+
reveal_type(f(0)) # N: Revealed type is "None"
6709+
reveal_type(f(1, foo='bar')) # N: Revealed type is "None"
6710+
reveal_type(f(1, y=2, foo='bar')) # N: Revealed type is "builtins.str"
6711+
f(1, **{'y': 0, 'z': 'a'}) # E: No overload variant of "f" matches argument types "int", "Dict[str, object]" \
6712+
# N: Possible overload variants: \
6713+
# N: def f(x: int = ..., **kwargs: str) -> None \
6714+
# N: def f(x: int = ..., *, y: int, **kwargs: str) -> str
6715+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)