Skip to content

Commit

Permalink
a few more S1/Self
Browse files Browse the repository at this point in the history
  • Loading branch information
twoertwein committed Aug 3, 2023
1 parent 68abe4d commit 2cfbdb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
13 changes: 6 additions & 7 deletions pandas-stubs/core/indexes/base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ from pandas._typing import (
Label,
Level,
NaPosition,
Scalar,
np_ndarray_anyint,
np_ndarray_bool,
np_ndarray_int64,
Expand Down Expand Up @@ -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=...
Expand Down Expand Up @@ -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]
Expand Down
25 changes: 2 additions & 23 deletions tests/test_indexes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2cfbdb0

Please sign in to comment.