Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on ParamSpec unification (for real) #16259

Merged
merged 1 commit into from
Oct 13, 2023
Merged
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
3 changes: 2 additions & 1 deletion mypy/expandtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,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 @@ -2013,3 +2013,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]