Skip to content

Spurious "No overload variant matches argument types" #4027

Closed

Description

@chadrik

I have an overloaded function that instantiates a class:

from typing import Any, Type, TypeVar, overload
T = TypeVar('T')

@overload
def make(cls: Type[T]) -> T:
    pass

@overload
def make() -> Any:
    pass

def make(cls=None):
    if cls:
        return cls()
    return object()

c = make(int)

reveal_type(c)

Type checking with mypy (using latest from master branch) results in the error:

[out]
a.py:17: error: No overload variant of "make" matches argument types [Overload(def (x: typing.SupportsInt =) -> builtins.int, def (x: Union[builtins.str, builtins.bytes], base: builtins.int =) -> builtins.int)]
a.py:19: error: Revealed type is 'Any'

Removing the overload prevents the error:

from typing import Type, TypeVar
T = TypeVar('T')

def make(cls: Type[T]) -> T:
    return cls()

c = make(int)

Is this a bug or user error?

thanks!

Activity

  1. JelleZijlstra commented on Sep 28, 2017

    @JelleZijlstra
    Member

    Looks like a bug to me. I think it may be translating the type int to a callable incorrectly, so it no longer matches Type.

  2. ilevkivskyi commented on Sep 28, 2017

    @ilevkivskyi
    Member

    Overloaded actual for Type[...]formal was just overlooked when implementing Type[...]. This would be essentially just a two-line fix.

  3. self-assigned this
    on Sep 28, 2017
  4. ilevkivskyi commented on Sep 30, 2017

    @ilevkivskyi
    Member

    As I promised here is a fix #4037

  5. chadrik commented on Sep 30, 2017

    @chadrik
    ContributorAuthor

    Thanks!

  6. added a commit that references this issue on Oct 2, 2017
    1aabd22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions