python / python/mypy

using a decorator on an overloaded function where the decorator uses `Concatenate` causes false positive "Overloaded function implementation does not accept all possible arguments" error

Open
#17,459 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-paramspec
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

from typing import Callable, Concatenate, TypeVar, overload, ParamSpec

T = TypeVar("T")
P = ParamSpec("P")
R = TypeVar("R")


def foo(fn: Callable[Concatenate[T, P], R]) -> Callable[Concatenate[T, P], R]:
    return fn


class Foo:
    @overload
    def bar(self, a: str) -> str: ...
    @overload
    def bar(self, a: int) -> int: ...

    # error: Overloaded function implementation does not accept all possible arguments of signature 1
    # error: Overloaded function implementation does not accept all possible arguments of signature 2
    @foo
    def bar(self, a: object) -> object: ...

playground

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided reproducer in the mypy playground and inspect how overloaded implementations are checked when the implementation is decorated with a Callable using Concatenate. Confirm the false-positive errors for both overloads, then verify that valid decorated overloads pass without weakening the existing argument-compatibility checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.