Skip to content

Commit 570443d

Browse files
committed
TYP: Use Self for type checking (remaining locations/)
1 parent 05424c2 commit 570443d

File tree

3 files changed

+6
-13
lines changed

3 files changed

+6
-13
lines changed

pandas/core/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Hashable,
1313
Iterator,
1414
Literal,
15-
TypeVar,
1615
cast,
1716
final,
1817
overload,
@@ -27,6 +26,7 @@
2726
DtypeObj,
2827
IndexLabel,
2928
NDFrameT,
29+
Self,
3030
Shape,
3131
npt,
3232
)
@@ -92,8 +92,6 @@
9292
"duplicated": "IndexOpsMixin",
9393
}
9494

95-
_T = TypeVar("_T", bound="IndexOpsMixin")
96-
9795

9896
class PandasObject(DirNamesMixin):
9997
"""
@@ -286,7 +284,7 @@ def _values(self) -> ExtensionArray | np.ndarray:
286284
raise AbstractMethodError(self)
287285

288286
@final
289-
def transpose(self: _T, *args, **kwargs) -> _T:
287+
def transpose(self, *args, **kwargs) -> Self:
290288
"""
291289
Return the transpose, which is by definition self.
292290

pandas/core/dtypes/base.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from pandas._libs.hashtable import object_hash
1818
from pandas._typing import (
1919
DtypeObj,
20+
Self,
2021
Shape,
2122
npt,
2223
type_t,
@@ -227,9 +228,7 @@ def empty(self, shape: Shape) -> type_t[ExtensionArray]:
227228
return cls._empty(shape, dtype=self)
228229

229230
@classmethod
230-
def construct_from_string(
231-
cls: type_t[ExtensionDtypeT], string: str
232-
) -> ExtensionDtypeT:
231+
def construct_from_string(cls, string: str) -> Self:
233232
r"""
234233
Construct this type from a string.
235234

pandas/core/indexing.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
TYPE_CHECKING,
77
Hashable,
88
Sequence,
9-
TypeVar,
109
cast,
1110
final,
1211
)
@@ -20,6 +19,7 @@
2019
from pandas._typing import (
2120
Axis,
2221
AxisInt,
22+
Self,
2323
)
2424
from pandas.compat import PYPY
2525
from pandas.errors import (
@@ -85,8 +85,6 @@
8585
Series,
8686
)
8787

88-
_LocationIndexerT = TypeVar("_LocationIndexerT", bound="_LocationIndexer")
89-
9088
# "null slice"
9189
_NS = slice(None, None)
9290
_one_ellipsis_message = "indexer may only contain one '...' entry"
@@ -669,9 +667,7 @@ class _LocationIndexer(NDFrameIndexerBase):
669667
_takeable: bool
670668

671669
@final
672-
def __call__(
673-
self: _LocationIndexerT, axis: Axis | None = None
674-
) -> _LocationIndexerT:
670+
def __call__(self, axis: Axis | None = None) -> Self:
675671
# we need to return a copy of ourselves
676672
new_self = type(self)(self.name, self.obj)
677673

0 commit comments

Comments
 (0)