Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ParamSpec seems to get lost with partial() #18589

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

Open
Dreamsorcerer opened this issue Feb 2, 2025 · 1 comment
Open

ParamSpec seems to get lost with partial() #18589

Dreamsorcerer opened this issue Feb 2, 2025 · 1 comment
Labels
bug mypy got something wrong topic-paramspec PEP 612, ParamSpec, Concatenate topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Feb 2, 2025

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 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
@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Feb 2, 2025
@A5rocks A5rocks added topic-paramspec PEP 612, ParamSpec, Concatenate topic-runtime-semantics mypy doesn't model runtime semantics correctly labels Feb 3, 2025
@A5rocks
Copy link
Collaborator

A5rocks commented Feb 3, 2025

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

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 topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

2 participants