Skip to content

ParamSpec seems to get lost with partial() #18589

Open

Description

@Dreamsorcerer

Bug Report

Trying to get ParamSpec working for async-lru, and currently testing out the new partial() support added last year, but it doesn't seem to work with our wrapper class.

To Reproduce

from functools import partial
from typing import Any, Callable, Coroutine, Generic, ParamSpec, TypeVar

_R = TypeVar("_R")
_P = ParamSpec("_P")

class Wrapper(Generic[_P, _R]):
    def __init__(self, fn: Callable[_P, Coroutine[Any, Any, _R]]) -> None:
        self.fn = fn

    async def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
        return await self.fn(*args, **kwargs)

async def coro(val: int) -> int:
    return val

async def test() -> None:
    coro_wrapped = Wrapper(coro)
    reveal_type(coro_wrapped)  # Revealed type is "Wrapper[[val: builtins.int], builtins.int]"
    await coro_wrapped(3, 2)  # error: Too many arguments for "__call__" of "Wrapper"  [call-arg]

    partial_wrapped = Wrapper(partial(coro, 2))
    reveal_type(partial_wrapped)  # Revealed type is "Wrapper[[*args: Any, **kwargs: Any], builtins.int]"
    await partial_wrapped(4)  # XXX: Should be an error here.

Your Environment

  • Mypy version used: 1.14.1
  • Python version used: 3.9

Activity

  1. A5rocks commented on Feb 3, 2025

    @A5rocks
    Collaborator

    For the record, this is a manifestation of #3832 because inferring signatures does not call the functools plugin for the functools.partial.__call__ signature.

  2. Dreamsorcerer commented on Jul 14, 2025

    @Dreamsorcerer
    ContributorAuthor

    That issue appears to be marked as fixed in 1.17 though, while this still one still happens.

  3. A5rocks commented on Jul 26, 2025

    @A5rocks
    Collaborator

    I thought it would but here's the comment about why it doesn't: #18943 (comment)

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, Concatenatetopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions