Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious "No overload variant matches argument types" #4027

Closed
chadrik opened this issue Sep 28, 2017 · 4 comments · Fixed by #4037
Closed

Spurious "No overload variant matches argument types" #4027

chadrik opened this issue Sep 28, 2017 · 4 comments · Fixed by #4037
Assignees
Labels
bug mypy got something wrong priority-1-normal

Comments

@chadrik
Copy link
Contributor

chadrik commented Sep 28, 2017

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!

@JelleZijlstra
Copy link
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.

@ilevkivskyi
Copy link
Member

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

@ilevkivskyi
Copy link
Member

As I promised here is a fix #4037

@chadrik
Copy link
Contributor Author

chadrik commented Sep 30, 2017

Thanks!

gvanrossum pushed a commit that referenced this issue Oct 2, 2017
Fixes #4027

Currently overloads on `Type[...]` don't accept class objects whose `__init__` is itself overloaded. I fix this by simply allowing `FunctionLike` with `.is_type_obj()` returning `True` instead of only `Callable`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants