Skip to content

First overload picked overeagerly when overloading on self type #14070

Open
@JelleZijlstra

Description

@JelleZijlstra

Consider this example:

from typing import Generic, TypeVar, Any, overload

AnyStr = TypeVar("AnyStr", str, bytes)

class Popen(Generic[AnyStr]):
    @overload
    def communicate(self: Popen[str], buf: str = ...) -> float: ...
    @overload
    def communicate(self: Popen[bytes], buf: memoryview | bytes = ...) -> range: ...
    def communicate(self, buf: object = None) -> Any: raise NotImplementedError

p = 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