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

Type variable re-scoping doesn't work under certain circumstances with higher-order functions #7867

Closed
LeeeeT opened this issue May 7, 2024 · 1 comment
Labels
as designed Not a bug, working as intended bug Something isn't working

Comments

@LeeeeT
Copy link

LeeeeT commented May 7, 2024

Prior to version 1.1.357 the following code was type checked as I expected.

from collections.abc import Callable


def d[T, R](c: Callable[[T], R]) -> Callable[[T], R]: ...


@d
def f[A, B](c: Callable[[list[A]], list[B]]) -> tuple[A, B]: ...


def id[T](value: T) -> T: ...


reveal_type(f(id))

The revealed type is tuple[A@f, A@f].

Starting with version 1.1.358, pyright is no longer able to determine the correct type of f(id), it is now tuple[Unknown, A@f]. I presume the regression was introduced by #7630 or #7634.

A few observations:

  • If you remove the @d decorator, it stops working on 1.1.357 either, although it doesn't change the type of the f function itself.
  • Wrapping A and B in list[] (or any other generic) in the f's signature prevents pyright from successfully re-scoping type variables; if you rewrite f as def f[A, B](c: Callable[[A], B]) -> tuple[A, B] it works.

I understand I'm in a gray area of the typing spec. Feel free to close this. 😔

@LeeeeT LeeeeT added the bug Something isn't working label May 7, 2024
@erictraut
Copy link
Collaborator

Closing this as "won't fix".

@erictraut erictraut closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
@erictraut erictraut added the as designed Not a bug, working as intended label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
as designed Not a bug, working as intended bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants