Skip to content

Commit 6b6504e

Browse files
ilevkivskyihauntsaninja
authored andcommitted
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 eb81e63 commit 6b6504e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

mypy/expandtype.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ def visit_callable_type(self, t: CallableType) -> CallableType:
342342
prefix = repl.prefix
343343
clean_repl = repl.copy_modified(prefix=Parameters([], [], []))
344344
return t.copy_modified(
345-
arg_types=self.expand_types(t.arg_types[:-2] + prefix.arg_types)
345+
arg_types=self.expand_types(t.arg_types[:-2])
346+
+ prefix.arg_types
346347
+ [
347348
clean_repl.with_flavor(ParamSpecFlavor.ARGS),
348349
clean_repl.with_flavor(ParamSpecFlavor.KWARGS),

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

+33
Original file line numberDiff line numberDiff line change
@@ -1876,3 +1876,36 @@ def event(event_handler: Callable[P, R_co]) -> Callable[P, R_co]: ...
18761876
@overload
18771877
def event(namespace: str, *args, **kwargs) -> HandlerDecorator: ...
18781878
[builtins fixtures/paramspec.pyi]
1879+
1880+
[case testParamSpecNoCrashOnUnificationPrefix]
1881+
from typing import Any, Callable, TypeVar, overload
1882+
from typing_extensions import ParamSpec, Concatenate
1883+
1884+
T = TypeVar("T")
1885+
U = TypeVar("U")
1886+
V = TypeVar("V")
1887+
W = TypeVar("W")
1888+
P = ParamSpec("P")
1889+
1890+
@overload
1891+
def call(
1892+
func: Callable[Concatenate[T, P], U],
1893+
x: T,
1894+
*args: Any,
1895+
**kwargs: Any,
1896+
) -> U: ...
1897+
@overload
1898+
def call(
1899+
func: Callable[Concatenate[T, U, P], V],
1900+
x: T,
1901+
y: U,
1902+
*args: Any,
1903+
**kwargs: Any,
1904+
) -> V: ...
1905+
def call(*args: Any, **kwargs: Any) -> Any: ...
1906+
1907+
def test1(x: int) -> str: ...
1908+
def test2(x: int, y: int) -> str: ...
1909+
reveal_type(call(test1, 1)) # N: Revealed type is "builtins.str"
1910+
reveal_type(call(test2, 1, 2)) # N: Revealed type is "builtins.str"
1911+
[builtins fixtures/paramspec.pyi]

0 commit comments

Comments
 (0)