Skip to content

Commit

Permalink
Fix overload issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Levkivskyi committed Aug 10, 2023
1 parent 2d21032 commit 59963c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,8 @@ def visit_callable_type(self, template: CallableType) -> list[Constraint]:
if (tk == ARG_STAR and ak != ARG_STAR) or (
tk == ARG_STAR2 and ak != ARG_STAR2
):
# Unpack may have shifted indices.
if not unpack_present:
if cactual.param_spec():
# TODO: we should be more careful also for non-ParamSpec functions
continue
if isinstance(a, ParamSpecType):
# TODO: can we infer something useful for *T vs P?
Expand Down
17 changes: 17 additions & 0 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -6569,3 +6569,20 @@ S = TypeVar("S", bound=str)
def foo(x: int = ...) -> Callable[[T], T]: ...
@overload
def foo(x: S = ...) -> Callable[[T], T]: ...

[case testOverloadGenericStarArgOverlap]
from typing import Any, Callable, TypeVar, overload, Union, Tuple, List

F = TypeVar("F", bound=Callable[..., Any])
S = TypeVar("S", bound=int)

def id(f: F) -> F: ...

@overload
def struct(*cols: S) -> int: ...
@overload
def struct(__cols: Union[List[S], Tuple[S, ...]]) -> int: ...
@id
def struct(*cols: Union[S, Union[List[S], Tuple[S, ...]]]) -> int:
pass
[builtins fixtures/tuple.pyi]

0 comments on commit 59963c4

Please sign in to comment.