Skip to content

Adding ParamSpec to an overloaded function causes default parameters to not be considered #5769

Backlog

Description

@Wizzerinus

Describe the Bug

In the following code:

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


def g():
    pass

P = ParamSpec("P")

@overload
def f(g: Callable[P, None], arg: Literal[False] = False, *args: P.args, **kwargs: P.kwargs) -> int | None: ...
@overload
def f(g: Callable[P, None], arg: Literal[True], *args: P.args, **kwargs: P.kwargs) -> None: ...

def f(g: Callable[P, None], arg: bool = False, *args: P.args, **kwargs: P.kwargs) -> int | None:
    raise NotImplementedError()

f(g)

f(g) is a correct call, as the first overloading allows arg to be inferred to be the default parameter False, and then P is empty.

Pyrefly gives this error:

ERROR sandbox.py:18: No matching overload found for function `f` called with arguments: (() -> None) [[no-matching-overload](https://pyrefly.org/en/docs/error-kinds/#no-matching-overload)]
  Possible overloads:
    ((ParamSpec(P)) -> None, Literal[False], ParamSpec(P)) -> int | None [closest match]
    ((ParamSpec(P)) -> None, Literal[True], ParamSpec(P)) -> None

Sandbox Link

https://pyrefly.org/sandbox/?project=v2.pVU9T8MwFPwrVrKYisZ7JiYkFmQJMTUd3GJCVGJHjgNFiP_O-SskDGnVTrFfbJ_93t29Rcs84SLRHObG-udLo0tyYUT71Mm9K17geE0T00IVKsXxvHEhrTJeZajiXTouSoNCTQl-w-G74NY2qizibe4FaLrFcX5wS1b4CyfghftiujogiSESRp6loE6UWEmKorgM2tENsfMQJ1hnQOxglle8aUJmBOyDc8BWKtDQazcIa9JJKC5zgyCYNNjmvQ-syMkzJo39Gk3K185fXptWoGEN7U4aeiwduL8EXCWhB0N5rbJHv6ok38efSOZ_UsoJDwESWQkuQoP1gFYFVKQsR5eS5M3ari8ZS9u1qZlU7EXvezbbwdwFifgQjc_u_DiivfR7HLug4amKO2Fs4wxhPaiD0p9q7ZI2V-iS7H4B

(Only applicable for extension issues) IDE Information

No response

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions