Skip to content

Matching generic return type of SupportsGetItem #11544

Description

@cmp0xff

Describe the bug

pyright does not match the generic return type of SupportsGetItem properly.

Code or Screenshots

from __future__ import annotations

from typing import TYPE_CHECKING, Any, TypeVar

if TYPE_CHECKING:
    from _typeshed import SupportsGetItem

class Series: ...

class DataFrame:
    def __getitem__(self, key: object) -> Series:
        return Series()

T = TypeVar("T")

def f(x: SupportsGetItem[Any, T]) -> T:
    if isinstance(x, DataFrame):
        return Series()
    else:
        return x[0]

VS Code extension or command-line

Type "Series" is not assignable to return type "T@f"
  Type "Series" is not assignable to type "T@f"  (reportReturnType)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions