Skip to content

False positive when using generic protocol in overload signature #5285

@erictraut

Description

@erictraut

From pandas-dev/pandas-stubs#729:

from typing import overload, Protocol, TypeVar, Any

AnyStr_contra = TypeVar("AnyStr_contra", str, bytes, contravariant=True)

class Buffer(Protocol):
    def __bytes__(self) -> bytes:
        ...

class BytesIO:
    def write(self, __b: Buffer) -> None:
        pass

class WriteBuffer(Protocol[AnyStr_contra]):
    def write(self, __b: AnyStr_contra) -> Any:
        ...

class NDFrame:
    @overload
    def to_csv(self, path_or_buf: WriteBuffer[bytes]) -> None:
        ...

    @overload
    def to_csv(self, path_or_buf: None = ...) -> str:
        ...

    def to_csv(self, path_or_buf: Any = None) -> Any:
        ...

def test_types_to_csv() -> None:
    df = NDFrame()
    df.to_csv(BytesIO())

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions