diff --git a/pandas-stubs/core/indexes/base.pyi b/pandas-stubs/core/indexes/base.pyi index 1f53b8b3..eff99f92 100644 --- a/pandas-stubs/core/indexes/base.pyi +++ b/pandas-stubs/core/indexes/base.pyi @@ -42,7 +42,6 @@ from pandas._typing import ( Label, Level, NaPosition, - Scalar, np_ndarray_anyint, np_ndarray_bool, np_ndarray_int64, @@ -193,7 +192,7 @@ class Index(IndexOpsMixin[S1], PandasObject): def __nonzero__(self) -> None: ... __bool__ = ... def union(self, other: list[HashableT] | Index, sort=...) -> Index: ... - def intersection(self, other: list[T1] | Self, sort: bool = ...) -> Self: ... + def intersection(self, other: list[T1] | Index, sort: bool = ...) -> Self: ... def difference(self, other: list | Index, sort: bool | None = None) -> Self: ... def symmetric_difference( self, other: list[T1] | Index, result_name=..., sort=... @@ -264,12 +263,12 @@ class Index(IndexOpsMixin[S1], PandasObject): def shape(self) -> tuple[int, ...]: ... # Extra methods from old stubs def __eq__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override] - def __iter__(self) -> Iterator: ... + def __iter__(self) -> Iterator[S1]: ... def __ne__(self, other: object) -> np_ndarray_bool: ... # type: ignore[override] - def __le__(self, other: Index | Scalar) -> np_ndarray_bool: ... # type: ignore[override] - def __ge__(self, other: Index | Scalar) -> np_ndarray_bool: ... # type: ignore[override] - def __lt__(self, other: Index | Scalar) -> np_ndarray_bool: ... # type: ignore[override] - def __gt__(self, other: Index | Scalar) -> np_ndarray_bool: ... # type: ignore[override] + def __le__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] + def __ge__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] + def __lt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] + def __gt__(self, other: Self | S1) -> np_ndarray_bool: ... # type: ignore[override] # overwrite inherit methods from OpsMixin @overload def __mul__( # type: ignore[misc] diff --git a/tests/test_indexes.py b/tests/test_indexes.py index 80ec5b3b..90b9bcbe 100644 --- a/tests/test_indexes.py +++ b/tests/test_indexes.py @@ -25,16 +25,6 @@ if TYPE_CHECKING: MYPY_CHECKING: bool = True - # See test_sorted_and_list() where mypy and pyright do different - # inference on sorted(pd.Index) - if MYPY_CHECKING: - from typing import Any - - from typing_extensions import TypeAlias - - SupportsRichComparison: TypeAlias = Any - else: - from _typeshed import SupportsRichComparison # noqa: F401 def test_index_unique() -> None: @@ -719,22 +709,11 @@ def test_interval_index_tuples(): def test_sorted_and_list() -> None: # GH 497 i1 = pd.Index([3, 2, 1]) - # mypy infers sorted(i1) as list[Any], while pyright infers sorted(i1) as - # list[SupportsRichComparison] check( - assert_type( - sorted(i1), - "list[SupportsRichComparison]", - ), - list, - ) - check( - assert_type( - list(i1), - list, - ), + assert_type(sorted(i1), list[int]), list, ) + check(assert_type(list(i1), list[int]), list) def test_index_operators() -> None: