Skip to content

First overload picked overeagerly when overloading on self type #14070

Description

@JelleZijlstra

Consider this example:

fromtypingimportGeneric, TypeVar, Any, overloadAnyStr=TypeVar("AnyStr", str, bytes)
classPopen(Generic[AnyStr]):
@overloaddefcommunicate(self: Popen[str], buf: str= ...) ->float: ...
@overloaddefcommunicate(self: Popen[bytes], buf: memoryview|bytes= ...) ->range: ...
defcommunicate(self, buf: object=None) ->Any: raiseNotImplementedErrorp=Popen()
reveal_type(p.communicate())

This currently reveals float. I think it should either be the union float | range or Any. This came up in python/typeshed#9100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions