Skip to content

Error with ParamSpec when it is in a Union type #11152

Closed as not planned
Closed as not planned

Description

@cmp0xff

Describe the bug

pyright does not process ParamSpec properly when it is in a Union type.

Code or Screenshots

from collections.abc import Callable
from typing import Concatenate, Literal, ParamSpec

P = ParamSpec("P")


def optr(
    num: int,
    fun: Callable[Concatenate[int, P], int] | Literal["plus1"] = "plus1",
    *args: P.args,
    **kwargs: P.kwargs,
) -> int:
    if fun == "plus1":
        return num + 1
    return fun(num, *args, **kwargs)


optr(1)  # pyright gives error: Arguments for ParamSpec "P@optr" are missing (reportCallIssue). mypy is fine with it.

VS Code extension or command-line

Command line, pyright 1.1.407

The issue arose from pandas-dev/pandas-stubs#1526.

Activity

  1. erictraut commented on Dec 4, 2025

    @erictraut
    Collaborator

    I think pyright's behavior here is correct. The value of P goes unsolved in your example.

    The correct way to annotate this function is with an overload.

    @overload
    def optr(num: int, fun: Literal["plus1"] = "plus1") -> int: ...
    @overload
    def optr[**P](
        num: int,
        fun: Callable[Concatenate[int, P], int],
        *args: P.args,
        **kwargs: P.kwargs,
    ) -> int: ...
    def optr(
        num: int,
        fun: Callable[Concatenate[int, ...], int] | Literal["plus1"] = "plus1",
        *args: Any,
        **kwargs: Any,
    ) -> int:
        if fun == "plus1":
            return num + 1
        return fun(num, *args, **kwargs)
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

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions