Skip to content

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

Closed

Description

@flaeppe

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

Activity

  1. A5rocks commented on Feb 12, 2023

    @A5rocks
    Collaborator

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

  2. hauntsaninja commented on Feb 12, 2023

    @hauntsaninja
    Collaborator

    Thanks for updating this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-paramspecPEP 612, ParamSpec, Concatenate

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions