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

Pyright hangs with reduce(lambda x, y: (x, y), ...) #9558

Open
kourbou opened this issue Dec 7, 2024 · 1 comment
Open

Pyright hangs with reduce(lambda x, y: (x, y), ...) #9558

kourbou opened this issue Dec 7, 2024 · 1 comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working

Comments

@kourbou
Copy link

kourbou commented Dec 7, 2024

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
@kourbou kourbou added the bug Something isn't working label Dec 7, 2024
@kourbou kourbou changed the title Pyright hangs indefinitely with functools.reduce(lambda x, y: (x, y), ...) Pyright hangs with reduce(lambda x, y: (x, y), ...) Dec 7, 2024
@LeeeeT
Copy link

LeeeeT commented Dec 7, 2024

This looks the same as #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.

erictraut added a commit that referenced this issue Dec 7, 2024
…rgument expression in certain circumstances. This addresses #9558 and #9536.
erictraut added a commit that referenced this issue Dec 7, 2024
…rgument expression in certain circumstances. This addresses #9558 and #9536. (#9560)
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants