Closed Andrej730 closed 1 week ago
I think pyright's behavior here is correct, so I don't consider this a bug.
Let's simplify the program to see what's going on here.
from typing import Any, Callable
def func[**P](func: Callable[P, Any], *args: P.args, **kwargs: P.kwargs):
...
func(lambda *args, **kwargs: None)
When a lambda is passed inline as an argument to another function, its parameter types are provided by the bidirectional inference context. In the code snippet above, the types of *args
and **kwargs
in the lambda are constrained to P.args
and P.kwargs
, respectively. They are not Any
.
If your intent is for the lambda to accept any parameters, then you would need to move the lambda outside of the call expression (as you've done with callback
above) or use a def
statement with explicit parameter type annotations.
See example below - providing already defined callback works fine but creating a lambda callback while calling
weakref.finalize
produces type errors (expected to work the same as with the previously defined callback)