Skip to content

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 #17459

Open

Description

@DetachHead
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

Activity

  1. ilevkivskyi commented on Jul 1, 2024

    @ilevkivskyi
    Member

    This is because foo() destroys the argument name for the first argument. Internally, I see the inferred type for implementation is

    def (__main__.Foo, a: builtins.object) -> builtins.object

    so it cannot accept call like Foo.bar(self=Foo(), a=1). This seems way too pedantic however.

  2. DetachHead commented on Jul 12, 2024

    @DetachHead
    ContributorAuthor

    imo self should be implicitly positional only. i can't think of a case where you'd want to specify it as a keyword argument

  3. erictraut commented on Jul 12, 2024

    @erictraut

    imo self should be implicitly positional only

    There was a discussion about this in the typing forum. The general consensus was aligned with this viewpoint, and this is what I've implemented in pyright, but this hasn't yet been formally incorporated into the typing spec. You're welcome to add your input to the discussion thread.

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, Concatenate

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions