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

Can't seem to type a decorator that works with ParamSpec on methods #16333

Open
Dreamsorcerer opened this issue Oct 26, 2023 · 0 comments
Open
Labels
bug mypy got something wrong

Comments

@Dreamsorcerer
Copy link
Contributor

I've been struggling with this one, and I'm not sure if I'm doing something wrong or mypy is doing something wrong:

from typing import Callable, Generic, ParamSpec, TypeVar

P = ParamSpec("P")
R = TypeVar("R")

class A(Generic[P, R]):
    def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R: ...

def decorator(fn: Callable[P, R]) -> A[P, R]: ...

class B:
    @decorator
    def foo(self) -> None: ...


b = B()
b.foo()  # error: Missing positional argument "self" in call to "__call__" of "A"  [call-arg]

I need the decorator, which returns the A wrapper, to work with both functions and methods.

Full project is at: aio-libs/async-lru#508

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Oct 26, 2023
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

1 participant