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

Generic type alias with param spec #15545

Closed
bersbersbers opened this issue Jun 29, 2023 · 3 comments
Closed

Generic type alias with param spec #15545

bersbersbers opened this issue Jun 29, 2023 · 3 comments
Labels
bug mypy got something wrong

Comments

@bersbersbers
Copy link

Bug Report

In the code below, decorator_pass works fine while decorator_fail fails. The only difference between the two is that I extracted Callable[[Method[C, P, T]], Method[C, P, T]] into its own variable (a generic type alias, if I am not mistaken).

I had expected this to be a duplicate of #11855, but that one is presumably fixed now.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.11&gist=077268582efbbbc19e671b7477cdadda

from typing import Any, Callable, Concatenate, ParamSpec, TypeVar

C = TypeVar("C")
P = ParamSpec("P")
T = TypeVar("T")
Method = Callable[Concatenate[C, P], T | None]

def decorator_pass() -> Callable[[Method[C, P, T]], Method[C, P, T]]:
    def decorator(func: Method[C, P, T]) -> Method[C, P, T]:
        def wrapper(self: C, /, *args: Any, **kwargs: Any) -> T | None:  # noqa: ANN401
            return func(self, *args, **kwargs)
        return wrapper
    return decorator

Wrapper = Callable[[Method[C, P, T]], Method[C, P, T]]
def decorator_fail() -> Wrapper[C, P, T]:
    def decorator(func: Method[C, P, T]) -> Method[C, P, T]:
        def wrapper(self: C, /, *args: Any, **kwargs: Any) -> T | None:  # noqa: ANN401
            return func(self, *args, **kwargs)
        return wrapper
    return decorator

class Class:
    @decorator_pass()
    def fun_pass(self, /) -> None:
        pass

    @decorator_fail()
    def fun_fail(self, /) -> None:
        pass

Expected Behavior

No error

Actual Behavior

main.py:28: error: Argument 1 has incompatible type "Callable[[Class], None]"; expected "Callable[[, VarArg(), KwArg()], | None]" [arg-type]

Your Environment

  • Mypy version used: 1.4.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11.4
@bersbersbers bersbersbers added the bug mypy got something wrong label Jun 29, 2023
@ilevkivskyi
Copy link
Member

This is a duplicate of #3924

@ilevkivskyi ilevkivskyi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2023
@hauntsaninja
Copy link
Collaborator

@bersbersbers is the project you were running into this on open source?

@bersbersbers
Copy link
Author

@bersbersbers is the project you were running into this on open source?

It may be one day, but if so, that day will be far out. So unfortunately, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants