Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mypy/meet.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,11 @@ def visit_type_var_tuple(self, t: TypeVarTupleType) -> ProperType:
return self.default(self.s)

def visit_unpack_type(self, t: UnpackType) -> ProperType:
raise NotImplementedError
if isinstance(self.s, UnpackType):
return UnpackType(self.meet(t.type, self.s.type))
if isinstance(self.s, Instance) and self.s.type.fullname == "builtins.object":
return t
return self.default(self.s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If safe_meet is enough, then this shouldn't be required?


def visit_parameters(self, t: Parameters) -> ProperType:
if isinstance(self.s, Parameters):
Expand Down
4 changes: 2 additions & 2 deletions mypy/typeops.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,15 +523,15 @@ def callable_corresponding_argument(

# def right(a: int = ...) -> None: ...
# def left(__a: int = ..., *, a: int = ...) -> None: ...
from mypy.meet import meet_types
from mypy.join import safe_meet

if (
not (by_name.required or by_pos.required)
and by_pos.name is None
and by_name.pos is None
):
return FormalArgument(
by_name.name, by_pos.pos, meet_types(by_name.typ, by_pos.typ), False
by_name.name, by_pos.pos, safe_meet(by_name.typ, by_pos.typ), False
)
return by_name if by_name is not None else by_pos

Expand Down
20 changes: 20 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -2599,3 +2599,23 @@ def run3(predicate: Callable[Concatenate[int, str, _P], None], *args: _P.args, *
# E: Argument 1 has incompatible type "*tuple[Union[int, str], ...]"; expected "str" \
# E: Argument 1 has incompatible type "*tuple[Union[int, str], ...]"; expected "_P.args"
[builtins fixtures/paramspec.pyi]

[case testParamSpecWithTypeVarTupleUnpack]
# Regression test for crash with ParamSpec and TypeVarTuple Unpack in meet.py
from typing import Callable, ParamSpec, TypeVar, TypeVarTuple, Unpack

P = ParamSpec("P")
T = TypeVar("T")
Ts = TypeVarTuple("Ts")

def call(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
return func(*args, **kwargs)

def run(func: Callable[[Unpack[Ts]], T], *args: Unpack[Ts], some_kwarg: str = "asdf") -> T:
...

def foo() -> str:
...

call(run, foo, some_kwarg="a") # E: Argument 1 to "call" has incompatible type "Callable[[Callable[[VarArg(Unpack[Ts])], T], VarArg(Unpack[Ts]), DefaultNamedArg(str, 'some_kwarg')], T]"; expected "Callable[[Callable[[], str], str], str]"
[builtins fixtures/paramspec.pyi]