Skip to content

Commit 186515f

Browse files
authored
Further fix overload diagnostic for vararg and varkwarg (#19619)
#19614 got merged faster than I expected :-)
1 parent adacbbf commit 186515f

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

mypy/typeops.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,18 +521,16 @@ def callable_corresponding_argument(
521521

522522
# def right(a: int = ...) -> None: ...
523523
# def left(__a: int = ..., *, a: int = ...) -> None: ...
524-
from mypy.subtypes import is_subtype
524+
from mypy.meet import meet_types
525525

526526
if (
527527
not (by_name.required or by_pos.required)
528528
and by_pos.name is None
529529
and by_name.pos is None
530530
):
531-
# We actually want the intersection of by_name.typ and by_pos.typ
532-
if is_subtype(by_name.typ, by_pos.typ):
533-
return FormalArgument(by_name.name, by_pos.pos, by_name.typ, False)
534-
if is_subtype(by_pos.typ, by_name.typ):
535-
return FormalArgument(by_name.name, by_pos.pos, by_pos.typ, False)
531+
return FormalArgument(
532+
by_name.name, by_pos.pos, meet_types(by_name.typ, by_pos.typ), False
533+
)
536534
return by_name if by_name is not None else by_pos
537535

538536

test-data/unit/check-overloading.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,23 @@ def foo(*args: int | str, **kw: int) -> None:
246246
pass
247247
[builtins fixtures/tuple.pyi]
248248

249+
[case testTypeCheckOverloadImplOverlapVarArgsAndKwargsUnion]
250+
from __future__ import annotations
251+
from typing import overload
252+
253+
class Foo: ...
254+
255+
@overload
256+
def foo(x: int) -> None: ...
257+
@overload
258+
def foo(*, x: Foo) -> None: ...
259+
@overload
260+
def foo(a: str, /) -> None: ...
261+
262+
def foo(*args: int | str, **kw: int | Foo) -> None:
263+
pass
264+
[builtins fixtures/tuple.pyi]
265+
249266
[case testTypeCheckOverloadWithImplTooSpecificRetType]
250267
from typing import overload, Any
251268

0 commit comments

Comments
 (0)