Skip to content

"Overloaded function implementation does not accept all possible arguments" #11391

Open

Description

@9999years

False positive; mypy doesn't believe that Foo[T] is a subtype of T.

from typing import Union, Generic, TypeVar, overload

T = TypeVar("T")

class Foo(Generic[T]):
    pass

@overload
def expect(pattern: Foo[T]) -> None: ...

@overload
def expect(pattern: T) -> None: ...

def expect(pattern: Union[Foo[T], T]) -> None: return None
$ mypy xxx.py
xxx.py:14: error: Overloaded function implementation does not accept all possible arguments of signature 1

Note that the second overload referencing the type variable used in the first overload is necessary; if pattern: int is used instead of pattern: T in the second overload, mypy type-checks the file correctly.

Environment

  • Mypy version used: 0.910
  • Python version used: 3.10 and 3.7
  • Operating system and version: Fedora 34

Related issues

I think that #10390 fixes this issue, but I'm not sure.

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

    bugtopic-overloads

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions