Skip to content

Spurious "No overload variant matches argument types" #4027

Description

@chadrik

I have an overloaded function that instantiates a class:

fromtypingimportAny, Type, TypeVar, overloadT=TypeVar('T')
@overloaddefmake(cls: Type[T]) ->T:
pass@overloaddefmake() ->Any:
passdefmake(cls=None):
ifcls:
returncls()
returnobject()
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:

fromtypingimportType, TypeVarT=TypeVar('T')
defmake(cls: Type[T]) ->T:
returncls()
c=make(int)

Is this a bug or user error?

thanks!

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions