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

ParamSpec errors when (re)used as generic argument #13403

Closed
flaeppe opened this issue Aug 13, 2022 · 2 comments
Closed

ParamSpec errors when (re)used as generic argument #13403

flaeppe opened this issue Aug 13, 2022 · 2 comments
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate

Comments

@flaeppe
Copy link

flaeppe commented Aug 13, 2022

Bug Report

Passing "through" a ParamSpec variable as argument up a generic class declaration chain generates errors.

I'm not sure if I'm taking an incorrect approach down here, but I'd like to be able to declare a decorator as a callable class that when decorating a function "disassembles" and copies the function signature on to the decorators __call__ signature.

To Reproduce

I'm running in to 2 slightly different errors when attempting the following two things. I can understand why I get the error on 1., but I'm a little bit confused by the error in 2.

  1. Passing a ParamSpec as argument, directly
from typing import Generic, ParamSpec

P = ParamSpec("P")

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

class Child(Base[P], Generic[P]):  # yields -> error: ParamSpec "P" is unbound
    ...
  1. Using a ParamSpec argument to assemble a callable, which is passed as new argument to a base class
from typing import Any, Callable, Generic, ParamSpec, TypeVar

P = ParamSpec("P")
C = TypeVar("C", bound=Callable[..., Any])

class Base(Generic[C]):
    def __init__(self, func: C) -> None:
        ...


class Child(Base[Callable[P, Any]], Generic[P]):  # yields -> error: The first argument to Callable must be a list of types, parameter specification, or "..."
    ...

Extended use case through playground

Expected Behavior

I'd like to be able to use a ParamSpec variable to pass on an expected definition to some base class.

Actual Behavior

Mypy yields errors when "passing" a ParamSpec as a generic error to some base class.

Your Environment

  • Mypy version used: 0.971
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files): -
  • Python version used: 3.10
  • Operating system and version: macOS Catalina 10.15.7
@A5rocks
Copy link
Contributor

A5rocks commented Feb 12, 2023

I think this works now! Check your mypy playground link -- since you were using latest it'll use mypy 1.0 which fixes this!

@hauntsaninja
Copy link
Collaborator

Thanks for updating this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate
Projects
None yet
Development

No branches or pull requests

4 participants