Skip to content

Generic class with ParamSpec isn't callable as far as partial is concerned #14802

Closed
@NeilGirdhar

Description

@NeilGirdhar
from collections.abc import Callable
from functools import partial
from typing import Generic, TypeVar

from typing_extensions import ParamSpec

R_co = TypeVar('R_co', covariant=True)
P = ParamSpec('P')

class X(Generic[P, R_co]):
    def __init__(self, f: Callable[P, R_co]):
        super().__init__()
        self.f = f

    def __call__(self, /, *args: P.args, **kwargs: P.kwargs) -> R_co:
        return self.f(*args, **kwargs)

@partial(X)  # error: Argument 1 to "partial" has incompatible type "Type[X[Any, Any]]"; expected "Callable[..., X[P, R_co]]"  [arg-type]
def f() -> int:
    return 2

print(f())

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