Skip to content

Commit 52eae4b

Browse files
committed
mypy happiness
1 parent 8ce8dd2 commit 52eae4b

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

pandas-stubs/_libs/tslibs/period.pyi

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ from typing import (
66
)
77

88
import numpy as np
9-
from pandas import (
10-
Index,
11-
PeriodIndex,
12-
Series,
13-
Timedelta,
14-
TimedeltaIndex,
15-
)
9+
from pandas.core.indexes.base import Index
10+
from pandas.core.indexes.period import PeriodIndex
11+
from pandas.core.indexes.timedeltas import TimedeltaIndex
12+
from pandas.core.series import Series
1613
from typing_extensions import Self
1714

1815
from pandas._libs.tslibs import NaTType
1916
from pandas._libs.tslibs.offsets import (
2017
BaseOffset,
2118
)
19+
from pandas._libs.tslibs.timedeltas import Timedelta
2220
from pandas._libs.tslibs.timestamps import Timestamp
2321
from pandas._typing import (
2422
PeriodFrequency,
@@ -79,7 +77,7 @@ class Period(PeriodMixin):
7977
@overload
8078
def __sub__(self, other: _PeriodAddSub) -> Period: ...
8179
@overload
82-
def __sub__(self, other: Period) -> BaseOffset: ...
80+
def __sub__(self, other: Self) -> BaseOffset: ...
8381
@overload
8482
def __sub__(self, other: NaTType) -> NaTType: ...
8583
@overload
@@ -95,23 +93,13 @@ class Period(PeriodMixin):
9593
@overload
9694
def __add__(self, other: NaTType) -> NaTType: ...
9795
@overload
98-
def __add__(self, other: Index) -> PeriodIndex: ...
99-
# Ignored due to indecipherable error from mypy:
100-
# Forward operator "__add__" is not callable [misc]
101-
@overload
10296
def __radd__(self, other: _PeriodAddSub) -> Self: ...
10397
@overload
10498
def __radd__(self, other: NaTType) -> NaTType: ...
105-
# Real signature is -> PeriodIndex, but conflicts with Index.__add__
106-
# Changing Index is very hard due to Index inheritance
107-
# Signatures of "__radd__" of "Period" and "__add__" of "Index"
108-
# are unsafely overlapping
109-
@overload
110-
def __radd__(self, other: Index) -> PeriodIndex: ...
11199
# ignore[misc] here because we know all other comparisons
112100
# are False, so we use Literal[False]
113101
@overload
114-
def __eq__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
102+
def __eq__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
115103
@overload
116104
def __eq__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
117105
@overload
@@ -121,7 +109,7 @@ class Period(PeriodMixin):
121109
@overload
122110
def __eq__(self, other: object) -> Literal[False]: ...
123111
@overload
124-
def __ge__(self, other: Period) -> bool: ...
112+
def __ge__(self, other: Self) -> bool: ...
125113
@overload
126114
def __ge__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
127115
@overload
@@ -133,7 +121,7 @@ class Period(PeriodMixin):
133121
self, other: np_ndarray[ShapeT, np.object_]
134122
) -> np_ndarray[ShapeT, np.bool]: ...
135123
@overload
136-
def __gt__(self, other: Period) -> bool: ...
124+
def __gt__(self, other: Self) -> bool: ...
137125
@overload
138126
def __gt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
139127
@overload
@@ -145,7 +133,7 @@ class Period(PeriodMixin):
145133
self, other: np_ndarray[ShapeT, np.object_]
146134
) -> np_ndarray[ShapeT, np.bool]: ...
147135
@overload
148-
def __le__(self, other: Period) -> bool: ...
136+
def __le__(self, other: Self) -> bool: ...
149137
@overload
150138
def __le__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
151139
@overload
@@ -157,7 +145,7 @@ class Period(PeriodMixin):
157145
self, other: np_ndarray[ShapeT, np.object_]
158146
) -> np_ndarray[ShapeT, np.bool]: ...
159147
@overload
160-
def __lt__(self, other: Period) -> bool: ...
148+
def __lt__(self, other: Self) -> bool: ...
161149
@overload
162150
def __lt__(self, other: PeriodIndex) -> np_1darray[np.bool]: ...
163151
@overload
@@ -171,7 +159,7 @@ class Period(PeriodMixin):
171159
# ignore[misc] here because we know all other comparisons
172160
# are False, so we use Literal[False]
173161
@overload
174-
def __ne__(self, other: Period) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
162+
def __ne__(self, other: Self) -> bool: ... # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload]
175163
@overload
176164
def __ne__(self, other: Index) -> np_1darray[np.bool]: ... # type: ignore[overload-overlap]
177165
@overload

pandas-stubs/core/indexes/base.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
512512
@overload
513513
def __add__(self, other: Index[Never]) -> Index: ...
514514
@overload
515+
def __add__(self: Index[Never], other: Period) -> PeriodIndex: ...
516+
@overload
515517
def __add__(
516518
self: Supports_ProtoAdd[_T_contra, S2], other: _T_contra | Sequence[_T_contra]
517519
) -> Index[S2]: ...
@@ -560,6 +562,8 @@ class Index(IndexOpsMixin[S1], ElementOpsMixin[S1]):
560562
@overload
561563
def __radd__(self: Index[Never], other: complex | _ListLike | Index) -> Index: ...
562564
@overload
565+
def __radd__(self: Index[Never], other: Period) -> PeriodIndex: ...
566+
@overload
563567
def __radd__(
564568
self: Supports_ProtoRAdd[_T_contra, S2],
565569
other: _T_contra | Sequence[_T_contra],

0 commit comments

Comments
 (0)