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]
Type "Series" is not assignable to return type "T@f"
Type "Series" is not assignable to type "T@f" (reportReturnType)
Describe the bug
pyrightdoes not match the generic return type ofSupportsGetItemproperly.Code or Screenshots
VS Code extension or command-line
mypyworks fine: https://mypy-play.net/?gist=3aaea716bd3429a90a96457884f46712pyrightreports an error: https://pyright-play.net/?strict=true&code=GYJw9gtgBA%2BjwFcAuCQFM5QJYQA5hCSgEMA7UsJYpLMUgZwFgAoF0SKJAT1y1IHNseAkQAqATQAKAURgBhABLS5AaQCSAOQDiAGigBBUlz2ieaAGrEQLFlmBQJM%2BUtWatALhZRvUdtBjcuGj0ABZoACZC%2BIRQAMoIuNFI9FpoSGpIaBA2zADGADbE9PRxaCBYwe5QAHS1OQVFJQAi1MQAYiDEEGiezD5Q4Wj2cPxpWJkQcAAU9Gj5wHoA1mhcVWAARgBWaLlIAJRQALQAfKXllV79PugoIKRnFfRTezmiUAC8DmaWIFMARKI-i9WMxBvZgFMAB5VeKJEQpNIZLIAbUMxgcAF0DicHL1%2BnZsPQ%2BPQqKRcmgoXoWlQOl00Hs8VdvDdUPdYmVHs9Lt45rNGUyWXcoJDkQAGDEsIA