From 07718f47885546f321dee4b82e361c580ed824a3 Mon Sep 17 00:00:00 2001 From: David Peter Date: Mon, 28 Apr 2025 16:40:35 +0200 Subject: [PATCH] [red-knot] Allow all callables to be assignable to @Todo-signatures (#17680) ## Summary Removes ~850 diagnostics related to assignability of callable types, where the callable-being-assigned-to has a "Todo signature", which should probably accept any left hand side callable/signature. --- .../resources/mdtest/annotations/callable.md | 12 ++++++++---- .../red_knot_python_semantic/src/types/signatures.rs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/red_knot_python_semantic/resources/mdtest/annotations/callable.md b/crates/red_knot_python_semantic/resources/mdtest/annotations/callable.md index e906b5de39..29cef6cae3 100644 --- a/crates/red_knot_python_semantic/resources/mdtest/annotations/callable.md +++ b/crates/red_knot_python_semantic/resources/mdtest/annotations/callable.md @@ -225,14 +225,16 @@ Using `Concatenate` as the first argument to `Callable`: from typing_extensions import Callable, Concatenate def _(c: Callable[Concatenate[int, str, ...], int]): - reveal_type(c) # revealed: (*args: @Todo(todo signature *args), **kwargs: @Todo(todo signature **kwargs)) -> int + # TODO: Should reveal the correct signature + reveal_type(c) # revealed: (...) -> int ``` And, as one of the parameter types: ```py def _(c: Callable[[Concatenate[int, str, ...], int], int]): - reveal_type(c) # revealed: (*args: @Todo(todo signature *args), **kwargs: @Todo(todo signature **kwargs)) -> int + # TODO: Should reveal the correct signature + reveal_type(c) # revealed: (...) -> int ``` ## Using `typing.ParamSpec` @@ -276,7 +278,8 @@ from typing_extensions import Callable, TypeVarTuple Ts = TypeVarTuple("Ts") def _(c: Callable[[int, *Ts], int]): - reveal_type(c) # revealed: (*args: @Todo(todo signature *args), **kwargs: @Todo(todo signature **kwargs)) -> int + # TODO: Should reveal the correct signature + reveal_type(c) # revealed: (...) -> int ``` And, using the legacy syntax using `Unpack`: @@ -285,7 +288,8 @@ And, using the legacy syntax using `Unpack`: from typing_extensions import Unpack def _(c: Callable[[int, Unpack[Ts]], int]): - reveal_type(c) # revealed: (*args: @Todo(todo signature *args), **kwargs: @Todo(todo signature **kwargs)) -> int + # TODO: Should reveal the correct signature + reveal_type(c) # revealed: (...) -> int ``` ## Member lookup diff --git a/crates/red_knot_python_semantic/src/types/signatures.rs b/crates/red_knot_python_semantic/src/types/signatures.rs index 4fcd669be2..811965cde9 100644 --- a/crates/red_knot_python_semantic/src/types/signatures.rs +++ b/crates/red_knot_python_semantic/src/types/signatures.rs @@ -895,7 +895,7 @@ impl<'db> Parameters<'db> { Parameter::keyword_variadic(Name::new_static("kwargs")) .with_annotated_type(todo_type!("todo signature **kwargs")), ], - is_gradual: false, + is_gradual: true, } }