Closed
Description
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!