Skip to content

Commit 67fb349

Browse files
authored
TYP: replace _SCT with _ScalarT (numpy#28690)
1 parent f50a15d commit 67fb349

30 files changed

+529
-529
lines changed

numpy/__init__.pyi

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -815,8 +815,8 @@ _1DShapeT = TypeVar("_1DShapeT", bound=_1D)
815815
_2DShapeT_co = TypeVar("_2DShapeT_co", bound=_2D, covariant=True)
816816
_1NShapeT = TypeVar("_1NShapeT", bound=tuple[L[1], Unpack[tuple[L[1], ...]]]) # (1,) | (1, 1) | (1, 1, 1) | ...
817817

818-
_SCT = TypeVar("_SCT", bound=generic)
819-
_SCT_co = TypeVar("_SCT_co", bound=generic, default=Any, covariant=True)
818+
_ScalarT = TypeVar("_ScalarT", bound=generic)
819+
_ScalarT_co = TypeVar("_ScalarT_co", bound=generic, default=Any, covariant=True)
820820
_NumberT = TypeVar("_NumberT", bound=number[Any])
821821
_RealNumberT = TypeVar("_RealNumberT", bound=floating | integer)
822822
_FloatingT_co = TypeVar("_FloatingT_co", bound=floating[Any], default=floating[Any], covariant=True)
@@ -893,7 +893,7 @@ _BuiltinObjectLike: TypeAlias = (
893893
) # fmt: skip
894894

895895
# Introduce an alias for `dtype` to avoid naming conflicts.
896-
_dtype: TypeAlias = dtype[_SCT]
896+
_dtype: TypeAlias = dtype[_ScalarT]
897897

898898
_ByteOrderChar: TypeAlias = L["<", ">", "=", "|"]
899899
# can be anything, is case-insensitive, and only the first character matters
@@ -1186,7 +1186,7 @@ class _DTypeMeta(type):
11861186
def _legacy(cls, /) -> bool: ...
11871187

11881188
@final
1189-
class dtype(Generic[_SCT_co], metaclass=_DTypeMeta):
1189+
class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
11901190
names: None | tuple[builtins.str, ...]
11911191
def __hash__(self) -> int: ...
11921192

@@ -1201,15 +1201,15 @@ class dtype(Generic[_SCT_co], metaclass=_DTypeMeta):
12011201
) -> dtype[float64]: ...
12021202

12031203
# Overload for `dtype` instances, scalar types, and instances that have a
1204-
# `dtype: dtype[_SCT]` attribute
1204+
# `dtype: dtype[_ScalarT]` attribute
12051205
@overload
12061206
def __new__(
12071207
cls,
1208-
dtype: _DTypeLike[_SCT],
1208+
dtype: _DTypeLike[_ScalarT],
12091209
align: builtins.bool = ...,
12101210
copy: builtins.bool = ...,
12111211
metadata: dict[builtins.str, Any] = ...,
1212-
) -> dtype[_SCT]: ...
1212+
) -> dtype[_ScalarT]: ...
12131213

12141214
# Builtin types
12151215
#
@@ -1607,7 +1607,7 @@ class dtype(Generic[_SCT_co], metaclass=_DTypeMeta):
16071607
@property
16081608
def str(self) -> LiteralString: ...
16091609
@property
1610-
def type(self) -> type[_SCT_co]: ...
1610+
def type(self) -> type[_ScalarT_co]: ...
16111611

16121612
@final
16131613
class flatiter(Generic[_ArrayT_co]):
@@ -1620,13 +1620,13 @@ class flatiter(Generic[_ArrayT_co]):
16201620
def index(self) -> int: ...
16211621
def copy(self) -> _ArrayT_co: ...
16221622
def __iter__(self) -> Self: ...
1623-
def __next__(self: flatiter[NDArray[_SCT]]) -> _SCT: ...
1623+
def __next__(self: flatiter[NDArray[_ScalarT]]) -> _ScalarT: ...
16241624
def __len__(self) -> int: ...
16251625
@overload
16261626
def __getitem__(
1627-
self: flatiter[NDArray[_SCT]],
1627+
self: flatiter[NDArray[_ScalarT]],
16281628
key: int | integer[Any] | tuple[int | integer[Any]],
1629-
) -> _SCT: ...
1629+
) -> _ScalarT: ...
16301630
@overload
16311631
def __getitem__(
16321632
self,
@@ -2041,11 +2041,11 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
20412041
@property
20422042
def size(self) -> int: ...
20432043
@property
2044-
def real(self: _HasDTypeWithRealAndImag[_SCT, object], /) -> ndarray[_ShapeT_co, dtype[_SCT]]: ...
2044+
def real(self: _HasDTypeWithRealAndImag[_ScalarT, object], /) -> ndarray[_ShapeT_co, dtype[_ScalarT]]: ...
20452045
@real.setter
20462046
def real(self, value: ArrayLike, /) -> None: ...
20472047
@property
2048-
def imag(self: _HasDTypeWithRealAndImag[object, _SCT], /) -> ndarray[_ShapeT_co, dtype[_SCT]]: ...
2048+
def imag(self: _HasDTypeWithRealAndImag[object, _ScalarT], /) -> ndarray[_ShapeT_co, dtype[_ScalarT]]: ...
20492049
@imag.setter
20502050
def imag(self, value: ArrayLike, /) -> None: ...
20512051

@@ -2377,12 +2377,12 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
23772377

23782378
@overload
23792379
def take( # type: ignore[misc]
2380-
self: NDArray[_SCT],
2380+
self: NDArray[_ScalarT],
23812381
indices: _IntLike_co,
23822382
axis: None | SupportsIndex = ...,
23832383
out: None = ...,
23842384
mode: _ModeKind = ...,
2385-
) -> _SCT: ...
2385+
) -> _ScalarT: ...
23862386
@overload
23872387
def take( # type: ignore[misc]
23882388
self,
@@ -2494,12 +2494,12 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
24942494
@overload
24952495
def astype(
24962496
self,
2497-
dtype: _DTypeLike[_SCT],
2497+
dtype: _DTypeLike[_ScalarT],
24982498
order: _OrderKACF = ...,
24992499
casting: _CastingKind = ...,
25002500
subok: builtins.bool = ...,
25012501
copy: builtins.bool | _CopyMode = ...,
2502-
) -> ndarray[_ShapeT_co, dtype[_SCT]]: ...
2502+
) -> ndarray[_ShapeT_co, dtype[_ScalarT]]: ...
25032503
@overload
25042504
def astype(
25052505
self,
@@ -2516,7 +2516,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
25162516
@overload # (dtype: T)
25172517
def view(self, /, dtype: _DTypeT | _HasDType[_DTypeT]) -> ndarray[_ShapeT_co, _DTypeT]: ...
25182518
@overload # (dtype: dtype[T])
2519-
def view(self, /, dtype: _DTypeLike[_SCT]) -> NDArray[_SCT]: ...
2519+
def view(self, /, dtype: _DTypeLike[_ScalarT]) -> NDArray[_ScalarT]: ...
25202520
@overload # (type: T)
25212521
def view(self, /, *, type: type[_ArrayT]) -> _ArrayT: ...
25222522
@overload # (_: T)
@@ -2528,7 +2528,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
25282528

25292529
def setfield(self, /, val: ArrayLike, dtype: DTypeLike, offset: CanIndex = 0) -> None: ...
25302530
@overload
2531-
def getfield(self, dtype: _DTypeLike[_SCT], offset: SupportsIndex = 0) -> NDArray[_SCT]: ...
2531+
def getfield(self, dtype: _DTypeLike[_ScalarT], offset: SupportsIndex = 0) -> NDArray[_ScalarT]: ...
25322532
@overload
25332533
def getfield(self, dtype: DTypeLike, offset: SupportsIndex = 0) -> NDArray[Any]: ...
25342534

@@ -2541,9 +2541,9 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
25412541
@overload # == 1-d & object_
25422542
def __iter__(self: ndarray[tuple[int], dtype[object_]], /) -> Iterator[Any]: ...
25432543
@overload # == 1-d
2544-
def __iter__(self: ndarray[tuple[int], dtype[_SCT]], /) -> Iterator[_SCT]: ...
2544+
def __iter__(self: ndarray[tuple[int], dtype[_ScalarT]], /) -> Iterator[_ScalarT]: ...
25452545
@overload # >= 2-d
2546-
def __iter__(self: ndarray[tuple[int, int, Unpack[tuple[int, ...]]], dtype[_SCT]], /) -> Iterator[NDArray[_SCT]]: ...
2546+
def __iter__(self: ndarray[tuple[int, int, Unpack[tuple[int, ...]]], dtype[_ScalarT]], /) -> Iterator[NDArray[_ScalarT]]: ...
25472547
@overload # ?-d
25482548
def __iter__(self, /) -> Iterator[Any]: ...
25492549

@@ -3571,12 +3571,12 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
35713571
@overload
35723572
def astype(
35733573
self,
3574-
dtype: _DTypeLike[_SCT],
3574+
dtype: _DTypeLike[_ScalarT],
35753575
order: _OrderKACF = ...,
35763576
casting: _CastingKind = ...,
35773577
subok: builtins.bool = ...,
35783578
copy: builtins.bool | _CopyMode = ...,
3579-
) -> _SCT: ...
3579+
) -> _ScalarT: ...
35803580
@overload
35813581
def astype(
35823582
self,
@@ -3594,9 +3594,9 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
35943594
@overload
35953595
def view(
35963596
self,
3597-
dtype: _DTypeLike[_SCT],
3597+
dtype: _DTypeLike[_ScalarT],
35983598
type: type[NDArray[Any]] = ...,
3599-
) -> _SCT: ...
3599+
) -> _ScalarT: ...
36003600
@overload
36013601
def view(
36023602
self,
@@ -3607,9 +3607,9 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
36073607
@overload
36083608
def getfield(
36093609
self,
3610-
dtype: _DTypeLike[_SCT],
3610+
dtype: _DTypeLike[_ScalarT],
36113611
offset: SupportsIndex = ...
3612-
) -> _SCT: ...
3612+
) -> _ScalarT: ...
36133613
@overload
36143614
def getfield(
36153615
self,
@@ -3747,21 +3747,21 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
37473747
self,
37483748
/,
37493749
axis: L[0, -1] | tuple[()] | None,
3750-
out: ndarray[tuple[()], dtype[_SCT]],
3750+
out: ndarray[tuple[()], dtype[_ScalarT]],
37513751
keepdims: SupportsIndex = False,
37523752
*,
37533753
where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True,
3754-
) -> _SCT: ...
3754+
) -> _ScalarT: ...
37553755
@overload
37563756
def all(
37573757
self,
37583758
/,
37593759
axis: L[0, -1] | tuple[()] | None = None,
37603760
*,
3761-
out: ndarray[tuple[()], dtype[_SCT]],
3761+
out: ndarray[tuple[()], dtype[_ScalarT]],
37623762
keepdims: SupportsIndex = False,
37633763
where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True,
3764-
) -> _SCT: ...
3764+
) -> _ScalarT: ...
37653765

37663766
@overload
37673767
def any(
@@ -3778,21 +3778,21 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
37783778
self,
37793779
/,
37803780
axis: L[0, -1] | tuple[()] | None,
3781-
out: ndarray[tuple[()], dtype[_SCT]],
3781+
out: ndarray[tuple[()], dtype[_ScalarT]],
37823782
keepdims: SupportsIndex = False,
37833783
*,
37843784
where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True,
3785-
) -> _SCT: ...
3785+
) -> _ScalarT: ...
37863786
@overload
37873787
def any(
37883788
self,
37893789
/,
37903790
axis: L[0, -1] | tuple[()] | None = None,
37913791
*,
3792-
out: ndarray[tuple[()], dtype[_SCT]],
3792+
out: ndarray[tuple[()], dtype[_ScalarT]],
37933793
keepdims: SupportsIndex = False,
37943794
where: builtins.bool | np.bool | ndarray[tuple[()], dtype[np.bool]] = True,
3795-
) -> _SCT: ...
3795+
) -> _ScalarT: ...
37963796

37973797
# Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
37983798
@property
@@ -5087,12 +5087,12 @@ class memmap(ndarray[_ShapeT_co, _DTypeT_co]):
50875087
def __new__(
50885088
subtype,
50895089
filename: StrOrBytesPath | _SupportsFileMethodsRW,
5090-
dtype: _DTypeLike[_SCT],
5090+
dtype: _DTypeLike[_ScalarT],
50915091
mode: _MemMapModeKind = ...,
50925092
offset: int = ...,
50935093
shape: None | int | tuple[int, ...] = ...,
50945094
order: _OrderKACF = ...,
5095-
) -> memmap[Any, dtype[_SCT]]: ...
5095+
) -> memmap[Any, dtype[_ScalarT]]: ...
50965096
@overload
50975097
def __new__(
50985098
subtype,
@@ -5302,35 +5302,35 @@ class matrix(ndarray[_2DShapeT_co, _DTypeT_co]):
53025302
def all(self, axis: None | _ShapeLike = ..., out: _ArrayT = ...) -> _ArrayT: ...
53035303

53045304
@overload
5305-
def max(self: NDArray[_SCT], axis: None = ..., out: None = ...) -> _SCT: ...
5305+
def max(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> _ScalarT: ...
53065306
@overload
53075307
def max(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, _DTypeT_co]: ...
53085308
@overload
53095309
def max(self, axis: None | _ShapeLike = ..., out: _ArrayT = ...) -> _ArrayT: ...
53105310

53115311
@overload
5312-
def min(self: NDArray[_SCT], axis: None = ..., out: None = ...) -> _SCT: ...
5312+
def min(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> _ScalarT: ...
53135313
@overload
53145314
def min(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, _DTypeT_co]: ...
53155315
@overload
53165316
def min(self, axis: None | _ShapeLike = ..., out: _ArrayT = ...) -> _ArrayT: ...
53175317

53185318
@overload
5319-
def argmax(self: NDArray[_SCT], axis: None = ..., out: None = ...) -> intp: ...
5319+
def argmax(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> intp: ...
53205320
@overload
53215321
def argmax(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, dtype[intp]]: ...
53225322
@overload
53235323
def argmax(self, axis: None | _ShapeLike = ..., out: _ArrayT = ...) -> _ArrayT: ...
53245324

53255325
@overload
5326-
def argmin(self: NDArray[_SCT], axis: None = ..., out: None = ...) -> intp: ...
5326+
def argmin(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> intp: ...
53275327
@overload
53285328
def argmin(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, dtype[intp]]: ...
53295329
@overload
53305330
def argmin(self, axis: None | _ShapeLike = ..., out: _ArrayT = ...) -> _ArrayT: ...
53315331

53325332
@overload
5333-
def ptp(self: NDArray[_SCT], axis: None = ..., out: None = ...) -> _SCT: ...
5333+
def ptp(self: NDArray[_ScalarT], axis: None = ..., out: None = ...) -> _ScalarT: ...
53345334
@overload
53355335
def ptp(self, axis: _ShapeLike, out: None = ...) -> matrix[_2D, _DTypeT_co]: ...
53365336
@overload

numpy/_core/defchararray.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ __all__ = [
9090
]
9191

9292
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
93-
_SCT = TypeVar("_SCT", bound=np.character)
93+
_CharacterT = TypeVar("_CharacterT", bound=np.character)
9494
_CharDTypeT_co = TypeVar("_CharDTypeT_co", bound=dtype[np.character], covariant=True)
95-
_CharArray: TypeAlias = chararray[tuple[int, ...], dtype[_SCT]]
95+
_CharArray: TypeAlias = chararray[tuple[int, ...], dtype[_CharacterT]]
9696

9797
_StringDTypeArray: TypeAlias = np.ndarray[_Shape, np.dtypes.StringDType]
9898
_StringDTypeSupportsArray: TypeAlias = _SupportsArray[np.dtypes.StringDType]

0 commit comments

Comments
 (0)