Skip to content

Commit

Permalink
Fix crash on ParamSpec unification (for real) (#16259)
Browse files Browse the repository at this point in the history
Fixes #16257

Parenthesis strike back. I hope this is the last place where I had put
them wrong.
  • Loading branch information
ilevkivskyi authored and hauntsaninja committed Oct 17, 2023
1 parent eb81e63 commit 6b6504e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def visit_callable_type(self, t: CallableType) -> CallableType:
prefix = repl.prefix
clean_repl = repl.copy_modified(prefix=Parameters([], [], []))
return t.copy_modified(
arg_types=self.expand_types(t.arg_types[:-2] + prefix.arg_types)
arg_types=self.expand_types(t.arg_types[:-2])
+ prefix.arg_types
+ [
clean_repl.with_flavor(ParamSpecFlavor.ARGS),
clean_repl.with_flavor(ParamSpecFlavor.KWARGS),
Expand Down
33 changes: 33 additions & 0 deletions test-data/unit/check-parameter-specification.test
Original file line number Diff line number Diff line change
Expand Up @@ -1876,3 +1876,36 @@ def event(event_handler: Callable[P, R_co]) -> Callable[P, R_co]: ...
@overload
def event(namespace: str, *args, **kwargs) -> HandlerDecorator: ...
[builtins fixtures/paramspec.pyi]

[case testParamSpecNoCrashOnUnificationPrefix]
from typing import Any, Callable, TypeVar, overload
from typing_extensions import ParamSpec, Concatenate

T = TypeVar("T")
U = TypeVar("U")
V = TypeVar("V")
W = TypeVar("W")
P = ParamSpec("P")

@overload
def call(
func: Callable[Concatenate[T, P], U],
x: T,
*args: Any,
**kwargs: Any,
) -> U: ...
@overload
def call(
func: Callable[Concatenate[T, U, P], V],
x: T,
y: U,
*args: Any,
**kwargs: Any,
) -> V: ...
def call(*args: Any, **kwargs: Any) -> Any: ...

def test1(x: int) -> str: ...
def test2(x: int, y: int) -> str: ...
reveal_type(call(test1, 1)) # N: Revealed type is "builtins.str"
reveal_type(call(test2, 1, 2)) # N: Revealed type is "builtins.str"
[builtins fixtures/paramspec.pyi]

0 comments on commit 6b6504e

Please sign in to comment.