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 on code involving polymorphic functions #8987

Open
LeeeeT opened this issue Sep 13, 2024 · 1 comment
Open

Pyright hangs on code involving polymorphic functions #8987

LeeeeT opened this issue Sep 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@LeeeeT
Copy link

LeeeeT commented Sep 13, 2024

Pyright hangs on the following code:

from collections.abc import Callable
from typing import Protocol


class MyProto(Protocol):
    def __call__[A, B](self, a: Callable[[A], B], b: Callable[[Callable[[A], B]], A]) -> B: ...


p: MyProto = lambda a: lambda b: a(b)

The code contains a type error on purpose.

@LeeeeT LeeeeT added the bug Something isn't working label Sep 13, 2024
@LeeeeT
Copy link
Author

LeeeeT commented Sep 13, 2024

If I fix the type error in the implementation...

p: MyProto = lambda a, b: a(b(a))

...pyright correctly shows no errors.

But if I then curry both the protocol and the implementation using my favorite ✨ curry 💅 function...

def curry[First, *Rest, Result](function: Callable[[First, *Rest], Result]) -> Callable[[*Rest], Callable[[First], Result]]:
    return lambda *rest: lambda first: function(first, *rest)


class MyProto(Protocol):
    @curry
    def __call__[A, B](self, a: Callable[[A], B], b: Callable[[Callable[[A], B]], A]) -> B: ...


p: MyProto = curry(lambda a, b: a(b(a)))

...pyright, again, hangs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant