Pyright hangs with `reduce(lambda x, y: (x, y), ...)`
Description
Pyright appears to hang indefinitely when calling functools.reduce with a tuple-ifying lambda.
Code
import functools
functools.reduce(lambda x, y: (x, y), range(3))
Environment
The code above was tested from the command-line, but is also verified to hang the language servers (for VS Code, Zed, ...).
$ pyright --version
pyright 1.1.390
This looks the same as https://github.com/microsoft/pyright/issues/9536.
The reason why it hangs in your example and mine is because we're returning a tuple from the lambda.
If I change the return type in your example to list (functools.reduce(lambda x, y: [x, y], range(3))), here's what pyright reports:
Type parameter "_T_co@Iterable" is covariant, but "int" is not a subtype of "list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[<Recursive>]]]]]]]]]]]]]]]]]]]]]"
"int" is not assignable to "list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[<Recursive>]]]]]]]]]]]]]]]]]]]]]"
Similar type gets revealed in my example too, if I change the return type to list:
def f[T](c: Callable[[T], T]) -> T: ...
reveal_type(f(lambda v: [v, v]))
Type of "f(lambda v: [v, v])" is "list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[list[<Recursive>]]]]]]]]]]]]]]]]]]]]]"
So I think the root cause is the same.
This is addressed in pyright 1.1.391.