Skip to content

Commit 2e52e98

Browse files
authored
Fix crash on ParamSpec unification (for real) (#16259)
Fixes #16257 Parenthesis strike back. I hope this is the last place where I had put them wrong.
1 parent fbc48af commit 2e52e98

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

mypy/expandtype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ def visit_callable_type(self, t: CallableType) -> CallableType:
348348
prefix = repl.prefix
349349
clean_repl = repl.copy_modified(prefix=Parameters([], [], []))
350350
return t.copy_modified(
351-
arg_types=self.expand_types(t.arg_types[:-2] + prefix.arg_types)
351+
arg_types=self.expand_types(t.arg_types[:-2])
352+
+ prefix.arg_types
352353
+ [
353354
clean_repl.with_flavor(ParamSpecFlavor.ARGS),
354355
clean_repl.with_flavor(ParamSpecFlavor.KWARGS),

test-data/unit/check-parameter-specification.test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,3 +2013,36 @@ def event(event_handler: Callable[P, R_co]) -> Callable[P, R_co]: ...
20132013
@overload
20142014
def event(namespace: str, *args, **kwargs) -> HandlerDecorator: ...
20152015
[builtins fixtures/paramspec.pyi]
2016+
2017+
[case testParamSpecNoCrashOnUnificationPrefix]
2018+
from typing import Any, Callable, TypeVar, overload
2019+
from typing_extensions import ParamSpec, Concatenate
2020+
2021+
T = TypeVar("T")
2022+
U = TypeVar("U")
2023+
V = TypeVar("V")
2024+
W = TypeVar("W")
2025+
P = ParamSpec("P")
2026+
2027+
@overload
2028+
def call(
2029+
func: Callable[Concatenate[T, P], U],
2030+
x: T,
2031+
*args: Any,
2032+
**kwargs: Any,
2033+
) -> U: ...
2034+
@overload
2035+
def call(
2036+
func: Callable[Concatenate[T, U, P], V],
2037+
x: T,
2038+
y: U,
2039+
*args: Any,
2040+
**kwargs: Any,
2041+
) -> V: ...
2042+
def call(*args: Any, **kwargs: Any) -> Any: ...
2043+
2044+
def test1(x: int) -> str: ...
2045+
def test2(x: int, y: int) -> str: ...
2046+
reveal_type(call(test1, 1)) # N: Revealed type is "builtins.str"
2047+
reveal_type(call(test2, 1, 2)) # N: Revealed type is "builtins.str"
2048+
[builtins fixtures/paramspec.pyi]

0 commit comments

Comments
 (0)