Skip to content

Commit 59963c4

Browse files
author
Ivan Levkivskyi
committed
Fix overload issue
1 parent 2d21032 commit 59963c4

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

mypy/constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -963,8 +963,8 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]:
963963
if (tk == ARG_STAR and ak != ARG_STAR) or (
964964
tk == ARG_STAR2 and ak != ARG_STAR2
965965
):
966-
# Unpack may have shifted indices.
967-
if not unpack_present:
966+
if cactual.param_spec():
967+
# TODO: we should be more careful also for non-ParamSpec functions
968968
continue
969969
if isinstance(a, ParamSpecType):
970970
# TODO: can we infer something useful for *T vs P?

test-data/unit/check-overloading.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,3 +6569,20 @@ S = TypeVar("S", bound=str)
65696569
def foo(x: int = ...) -> Callable[[T], T]: ...
65706570
@overload
65716571
def foo(x: S = ...) -> Callable[[T], T]: ...
6572+
6573+
[case testOverloadGenericStarArgOverlap]
6574+
from typing import Any, Callable, TypeVar, overload, Union, Tuple, List
6575+
6576+
F = TypeVar("F", bound=Callable[..., Any])
6577+
S = TypeVar("S", bound=int)
6578+
6579+
def id(f: F) -> F: ...
6580+
6581+
@overload
6582+
def struct(*cols: S) -> int: ...
6583+
@overload
6584+
def struct(__cols: Union[List[S], Tuple[S, ...]]) -> int: ...
6585+
@id
6586+
def struct(*cols: Union[S, Union[List[S], Tuple[S, ...]]]) -> int:
6587+
pass
6588+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)