Skip to content

Commit 6c86b9b

Browse files
committed
Allow partial overlap when checking overload alternatives
1 parent 3c91647 commit 6c86b9b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

mypy/checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
548548
# Is the overload alternative's arguments subtypes of the implementation's?
549549
if not is_callable_compatible(impl, sig1,
550550
is_compat=is_subtype_no_promote,
551+
allow_partial_overlap=True,
551552
ignore_return=True):
552553
self.msg.overloaded_signatures_arg_specific(i + 1, defn.impl)
553554

test-data/unit/check-overloading.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5173,3 +5173,25 @@ def f2(g: G[A, Any]) -> A: ... # E: Overloaded function signatures 1 and 2 over
51735173
@overload
51745174
def f2(g: G[A, B], x: int = ...) -> B: ...
51755175
def f2(g: Any, x: int = ...) -> Any: ...
5176+
5177+
[case testOverloadKeywordArgsAndKwargs]
5178+
from typing import Optional, overload
5179+
5180+
@overload
5181+
def f(x: int = 0, **kwargs: str) -> None:
5182+
...
5183+
@overload
5184+
def f(x: int = 0, *, y: int, **kwargs: str) -> str:
5185+
...
5186+
def f(x: int = 0, *, y: Optional[int] = None, **kwargs: str) -> Optional[str]:
5187+
...
5188+
5189+
reveal_type(f(0)) # N: Revealed type is "None"
5190+
reveal_type(f(1, foo='bar')) # N: Revealed type is "None"
5191+
reveal_type(f(1, y=2, foo='bar')) # N: Revealed type is "builtins.str"
5192+
f(1, **{'y': 0, 'z': 'a'}) # E: No overload variant of "f" matches argument types "int", "Dict[str, object]" \
5193+
# N: Possible overload variants: \
5194+
# N: def f(x: int = ..., **kwargs: str) -> None \
5195+
# N: def f(x: int = ..., *, y: int, **kwargs: str) -> str
5196+
5197+
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)