Skip to content

Commit 19da938

Browse files
committed
Allow partial overlap when checking overload alternatives
1 parent 7576f65 commit 19da938

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

mypy/checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
556556
# Is the overload alternative's arguments subtypes of the implementation's?
557557
if not is_callable_compatible(impl, sig1,
558558
is_compat=is_subtype_no_promote,
559+
allow_partial_overlap=True,
559560
ignore_return=True):
560561
self.msg.overloaded_signatures_arg_specific(i + 1, defn.impl)
561562

test-data/unit/check-overloading.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5337,3 +5337,24 @@ def register(cls: Any) -> Any: return None
53375337
x = register(Foo)
53385338
reveal_type(x) # N: Revealed type is "builtins.int"
53395339
[builtins fixtures/dict.pyi]
5340+
5341+
[case testOverloadKeywordArgsAndKwargs]
5342+
from typing import Optional, overload
5343+
5344+
@overload
5345+
def f(x: int = 0, **kwargs: str) -> None:
5346+
...
5347+
@overload
5348+
def f(x: int = 0, *, y: int, **kwargs: str) -> str:
5349+
...
5350+
def f(x: int = 0, *, y: Optional[int] = None, **kwargs: str) -> Optional[str]:
5351+
...
5352+
5353+
reveal_type(f(0)) # N: Revealed type is "None"
5354+
reveal_type(f(1, foo='bar')) # N: Revealed type is "None"
5355+
reveal_type(f(1, y=2, foo='bar')) # N: Revealed type is "builtins.str"
5356+
f(1, **{'y': 0, 'z': 'a'}) # E: No overload variant of "f" matches argument types "int", "Dict[str, object]" \
5357+
# N: Possible overload variants: \
5358+
# N: def f(x: int = ..., **kwargs: str) -> None \
5359+
# N: def f(x: int = ..., *, y: int, **kwargs: str) -> str
5360+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)