Skip to content

Commit 8f11c7b

Browse files
authored
TYP: rename _ShapeType TypeVar to _ShapeT (numpy#28688)
1 parent 2bfef66 commit 8f11c7b

File tree

9 files changed

+57
-57
lines changed

9 files changed

+57
-57
lines changed

numpy/__init__.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,8 @@ __all__ = [ # noqa: RUF022
769769
# Only use these for functions; never as generic type parameter.
770770

771771
_AnyStr = TypeVar("_AnyStr", LiteralString, str, bytes)
772-
_AnyShapeType = TypeVar(
773-
"_AnyShapeType",
772+
_AnyShapeT = TypeVar(
773+
"_AnyShapeT",
774774
tuple[()], # 0-d
775775
tuple[int], # 1-d
776776
tuple[int, int], # 2-d
@@ -2424,12 +2424,12 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
24242424
@overload # (() | (int) | (int, int) | ....) # up to 8-d
24252425
def reshape(
24262426
self,
2427-
shape: _AnyShapeType,
2427+
shape: _AnyShapeT,
24282428
/,
24292429
*,
24302430
order: _OrderACF = "C",
24312431
copy: builtins.bool | None = None,
2432-
) -> ndarray[_AnyShapeType, _DType_co]: ...
2432+
) -> ndarray[_AnyShapeT, _DType_co]: ...
24332433
@overload # (index)
24342434
def reshape(
24352435
self,
@@ -2601,13 +2601,13 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DType_co]):
26012601

26022602
# TODO: Uncomment once https://github.com/python/mypy/issues/14070 is fixed
26032603
# @overload
2604-
# def __abs__(self: ndarray[_ShapeType, dtypes.Complex64DType], /) -> ndarray[_ShapeType, dtypes.Float32DType]: ...
2604+
# def __abs__(self: ndarray[_ShapeT, dtypes.Complex64DType], /) -> ndarray[_ShapeT, dtypes.Float32DType]: ...
26052605
# @overload
2606-
# def __abs__(self: ndarray[_ShapeType, dtypes.Complex128DType], /) -> ndarray[_ShapeType, dtypes.Float64DType]: ...
2606+
# def __abs__(self: ndarray[_ShapeT, dtypes.Complex128DType], /) -> ndarray[_ShapeT, dtypes.Float64DType]: ...
26072607
# @overload
2608-
# def __abs__(self: ndarray[_ShapeType, dtypes.CLongDoubleDType], /) -> ndarray[_ShapeType, dtypes.LongDoubleDType]: ...
2608+
# def __abs__(self: ndarray[_ShapeT, dtypes.CLongDoubleDType], /) -> ndarray[_ShapeT, dtypes.LongDoubleDType]: ...
26092609
# @overload
2610-
# def __abs__(self: ndarray[_ShapeType, dtype[complex128]], /) -> ndarray[_ShapeType, dtype[float64]]: ...
2610+
# def __abs__(self: ndarray[_ShapeT, dtype[complex128]], /) -> ndarray[_ShapeT, dtype[float64]]: ...
26112611
@overload
26122612
def __abs__(self: ndarray[_ShapeT, dtype[complexfloating[_NBit]]], /) -> ndarray[_ShapeT, dtype[floating[_NBit]]]: ...
26132613
@overload
@@ -3655,7 +3655,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
36553655
order: _OrderACF = "C",
36563656
copy: builtins.bool | None = None,
36573657
) -> Self: ...
3658-
@overload # ((1, *(1, ...))@_ShapeType)
3658+
@overload # ((1, *(1, ...))@_ShapeT)
36593659
def reshape(
36603660
self,
36613661
shape: _1NShapeT,

numpy/_core/fromnumeric.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from numpy import (
2727
timedelta64,
2828
object_,
2929
generic,
30-
_AnyShapeType,
30+
_AnyShapeT,
3131
_OrderKACF,
3232
_OrderACF,
3333
_ModeKind,
@@ -109,14 +109,14 @@ __all__ = [
109109
_SCT = TypeVar("_SCT", bound=generic)
110110
_SCT_uifcO = TypeVar("_SCT_uifcO", bound=number[Any] | object_)
111111
_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any])
112-
_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...])
113-
_ShapeType_co = TypeVar("_ShapeType_co", bound=tuple[int, ...], covariant=True)
112+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
113+
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
114114

115115
@type_check_only
116-
class _SupportsShape(Protocol[_ShapeType_co]):
116+
class _SupportsShape(Protocol[_ShapeT_co]):
117117
# NOTE: it matters that `self` is positional only
118118
@property
119-
def shape(self, /) -> _ShapeType_co: ...
119+
def shape(self, /) -> _ShapeT_co: ...
120120

121121
# a "sequence" that isn't a string, bytes, bytearray, or memoryview
122122
_T = TypeVar("_T")
@@ -184,14 +184,14 @@ def reshape( # shape: index
184184
copy: bool | None = None,
185185
) -> np.ndarray[tuple[int], np.dtype[_SCT]]: ...
186186
@overload
187-
def reshape( # shape: (int, ...) @ _AnyShapeType
187+
def reshape( # shape: (int, ...) @ _AnyShapeT
188188
a: _ArrayLike[_SCT],
189189
/,
190-
shape: _AnyShapeType,
190+
shape: _AnyShapeT,
191191
order: _OrderACF = "C",
192192
*,
193193
copy: bool | None = None,
194-
) -> np.ndarray[_AnyShapeType, np.dtype[_SCT]]: ...
194+
) -> np.ndarray[_AnyShapeT, np.dtype[_SCT]]: ...
195195
@overload # shape: Sequence[index]
196196
def reshape(
197197
a: _ArrayLike[_SCT],
@@ -211,14 +211,14 @@ def reshape(
211211
copy: bool | None = None,
212212
) -> np.ndarray[tuple[int], np.dtype[Any]]: ...
213213
@overload
214-
def reshape( # shape: (int, ...) @ _AnyShapeType
214+
def reshape( # shape: (int, ...) @ _AnyShapeT
215215
a: ArrayLike,
216216
/,
217-
shape: _AnyShapeType,
217+
shape: _AnyShapeT,
218218
order: _OrderACF = "C",
219219
*,
220220
copy: bool | None = None,
221-
) -> np.ndarray[_AnyShapeType, np.dtype[Any]]: ...
221+
) -> np.ndarray[_AnyShapeT, np.dtype[Any]]: ...
222222
@overload # shape: Sequence[index]
223223
def reshape(
224224
a: ArrayLike,
@@ -460,13 +460,13 @@ def searchsorted(
460460
@overload
461461
def resize(a: _ArrayLike[_SCT], new_shape: SupportsIndex | tuple[SupportsIndex]) -> np.ndarray[tuple[int], np.dtype[_SCT]]: ...
462462
@overload
463-
def resize(a: _ArrayLike[_SCT], new_shape: _AnyShapeType) -> np.ndarray[_AnyShapeType, np.dtype[_SCT]]: ...
463+
def resize(a: _ArrayLike[_SCT], new_shape: _AnyShapeT) -> np.ndarray[_AnyShapeT, np.dtype[_SCT]]: ...
464464
@overload
465465
def resize(a: _ArrayLike[_SCT], new_shape: _ShapeLike) -> NDArray[_SCT]: ...
466466
@overload
467467
def resize(a: ArrayLike, new_shape: SupportsIndex | tuple[SupportsIndex]) -> np.ndarray[tuple[int], np.dtype[Any]]: ...
468468
@overload
469-
def resize(a: ArrayLike, new_shape: _AnyShapeType) -> np.ndarray[_AnyShapeType, np.dtype[Any]]: ...
469+
def resize(a: ArrayLike, new_shape: _AnyShapeT) -> np.ndarray[_AnyShapeT, np.dtype[Any]]: ...
470470
@overload
471471
def resize(a: ArrayLike, new_shape: _ShapeLike) -> NDArray[Any]: ...
472472

@@ -558,7 +558,7 @@ def nonzero(a: _ArrayLike[Any]) -> tuple[NDArray[intp], ...]: ...
558558
@overload
559559
def shape(a: _SupportsShape[Never]) -> tuple[int, ...]: ...
560560
@overload
561-
def shape(a: _SupportsShape[_ShapeType]) -> _ShapeType: ...
561+
def shape(a: _SupportsShape[_ShapeT]) -> _ShapeT: ...
562562
@overload
563563
def shape(a: _PyScalar) -> tuple[()]: ...
564564
# `collections.abc.Sequence` can't be used hesre, since `bytes` and `str` are

numpy/_core/multiarray.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ from numpy import ( # type: ignore[attr-defined]
4949
signedinteger,
5050
floating,
5151
complexfloating,
52-
_AnyShapeType,
52+
_AnyShapeT,
5353
_OrderKACF,
5454
_OrderCF,
5555
_CastingKind,
@@ -288,38 +288,38 @@ class _ConstructorEmpty(Protocol):
288288
def __call__(
289289
self,
290290
/,
291-
shape: _AnyShapeType,
291+
shape: _AnyShapeT,
292292
dtype: None = ...,
293293
order: _OrderCF = ...,
294294
**kwargs: Unpack[_KwargsEmpty],
295-
) -> _Array[_AnyShapeType, float64]: ...
295+
) -> _Array[_AnyShapeT, float64]: ...
296296
@overload
297297
def __call__(
298298
self,
299299
/,
300-
shape: _AnyShapeType,
300+
shape: _AnyShapeT,
301301
dtype: _DType | _SupportsDType[_DType],
302302
order: _OrderCF = ...,
303303
**kwargs: Unpack[_KwargsEmpty],
304-
) -> ndarray[_AnyShapeType, _DType]: ...
304+
) -> ndarray[_AnyShapeT, _DType]: ...
305305
@overload
306306
def __call__(
307307
self,
308308
/,
309-
shape: _AnyShapeType,
309+
shape: _AnyShapeT,
310310
dtype: type[_SCT],
311311
order: _OrderCF = ...,
312312
**kwargs: Unpack[_KwargsEmpty],
313-
) -> _Array[_AnyShapeType, _SCT]: ...
313+
) -> _Array[_AnyShapeT, _SCT]: ...
314314
@overload
315315
def __call__(
316316
self,
317317
/,
318-
shape: _AnyShapeType,
318+
shape: _AnyShapeT,
319319
dtype: DTypeLike | None = ...,
320320
order: _OrderCF = ...,
321321
**kwargs: Unpack[_KwargsEmpty],
322-
) -> _Array[_AnyShapeType, Any]: ...
322+
) -> _Array[_AnyShapeT, Any]: ...
323323

324324
# unknown shape
325325
@overload

numpy/_core/numeric.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ from numpy import (
4444
float64,
4545
timedelta64,
4646
object_,
47-
_AnyShapeType,
47+
_AnyShapeT,
4848
_OrderKACF,
4949
_OrderCF,
5050
)
@@ -191,7 +191,7 @@ _T = TypeVar("_T")
191191
_SCT = TypeVar("_SCT", bound=generic)
192192
_DType = TypeVar("_DType", bound=np.dtype[Any])
193193
_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any])
194-
_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...])
194+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
195195

196196
_CorrelateMode: TypeAlias = L["valid", "same", "full"]
197197

@@ -316,36 +316,36 @@ def full(
316316
# known shape
317317
@overload
318318
def full(
319-
shape: _AnyShapeType,
319+
shape: _AnyShapeT,
320320
fill_value: _SCT,
321321
dtype: None = ...,
322322
order: _OrderCF = ...,
323323
**kwargs: Unpack[_KwargsEmpty],
324-
) -> _Array[_AnyShapeType, _SCT]: ...
324+
) -> _Array[_AnyShapeT, _SCT]: ...
325325
@overload
326326
def full(
327-
shape: _AnyShapeType,
327+
shape: _AnyShapeT,
328328
fill_value: Any,
329329
dtype: _DType | _SupportsDType[_DType],
330330
order: _OrderCF = ...,
331331
**kwargs: Unpack[_KwargsEmpty],
332-
) -> np.ndarray[_AnyShapeType, _DType]: ...
332+
) -> np.ndarray[_AnyShapeT, _DType]: ...
333333
@overload
334334
def full(
335-
shape: _AnyShapeType,
335+
shape: _AnyShapeT,
336336
fill_value: Any,
337337
dtype: type[_SCT],
338338
order: _OrderCF = ...,
339339
**kwargs: Unpack[_KwargsEmpty],
340-
) -> _Array[_AnyShapeType, _SCT]: ...
340+
) -> _Array[_AnyShapeT, _SCT]: ...
341341
@overload
342342
def full(
343-
shape: _AnyShapeType,
343+
shape: _AnyShapeT,
344344
fill_value: Any,
345345
dtype: None | DTypeLike = ...,
346346
order: _OrderCF = ...,
347347
**kwargs: Unpack[_KwargsEmpty],
348-
) -> _Array[_AnyShapeType, Any]: ...
348+
) -> _Array[_AnyShapeT, Any]: ...
349349
# unknown shape
350350
@overload
351351
def full(
@@ -862,19 +862,19 @@ def array_equiv(a1: ArrayLike, a2: ArrayLike) -> bool: ...
862862

863863
@overload
864864
def astype(
865-
x: ndarray[_ShapeType, dtype[Any]],
865+
x: ndarray[_ShapeT, dtype[Any]],
866866
dtype: _DTypeLike[_SCT],
867867
/,
868868
*,
869869
copy: bool = ...,
870870
device: None | L["cpu"] = ...,
871-
) -> ndarray[_ShapeType, dtype[_SCT]]: ...
871+
) -> ndarray[_ShapeT, dtype[_SCT]]: ...
872872
@overload
873873
def astype(
874-
x: ndarray[_ShapeType, dtype[Any]],
874+
x: ndarray[_ShapeT, dtype[Any]],
875875
dtype: DTypeLike,
876876
/,
877877
*,
878878
copy: bool = ...,
879879
device: None | L["cpu"] = ...,
880-
) -> ndarray[_ShapeType, dtype[Any]]: ...
880+
) -> ndarray[_ShapeT, dtype[Any]]: ...

numpy/ma/core.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ __all__ = [
217217
"zeros_like",
218218
]
219219

220-
_ShapeType = TypeVar("_ShapeType", bound=tuple[int, ...])
221-
_ShapeType_co = TypeVar("_ShapeType_co", bound=tuple[int, ...], covariant=True)
220+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
221+
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
222222
_DType = TypeVar("_DType", bound=dtype[Any])
223223
_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True)
224224
_ArrayT = TypeVar("_ArrayT", bound=ndarray[Any, Any])
@@ -371,7 +371,7 @@ class MaskedIterator:
371371
def __setitem__(self, index, value): ...
372372
def __next__(self): ...
373373

374-
class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
374+
class MaskedArray(ndarray[_ShapeT_co, _DType_co]):
375375
__array_priority__: Any
376376
def __new__(cls, data=..., mask=..., dtype=..., copy=..., subok=..., ndmin=..., fill_value=..., keep_mask=..., hard_mask=..., shrink=..., order=...): ...
377377
def __array_finalize__(self, obj): ...
@@ -384,9 +384,9 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
384384
@dtype.setter
385385
def dtype(self: MaskedArray[Any, _DType], dtype: _DType, /) -> None: ...
386386
@property
387-
def shape(self) -> _ShapeType_co: ...
387+
def shape(self) -> _ShapeT_co: ...
388388
@shape.setter
389-
def shape(self: MaskedArray[_ShapeType, Any], shape: _ShapeType, /) -> None: ...
389+
def shape(self: MaskedArray[_ShapeT, Any], shape: _ShapeT, /) -> None: ...
390390
def __setmask__(self, mask, copy=...): ...
391391
@property
392392
def mask(self): ...
@@ -745,7 +745,7 @@ class MaskedArray(ndarray[_ShapeType_co, _DType_co]):
745745
def __reduce__(self): ...
746746
def __deepcopy__(self, memo=...): ...
747747

748-
class mvoid(MaskedArray[_ShapeType_co, _DType_co]):
748+
class mvoid(MaskedArray[_ShapeT_co, _DType_co]):
749749
def __new__(
750750
self, # pyright: ignore[reportSelfClsParameterName]
751751
data,

numpy/ma/mrecords.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ __all__ = [
1212
"addfield",
1313
]
1414

15-
_ShapeType_co = TypeVar("_ShapeType_co", covariant=True, bound=tuple[int, ...])
15+
_ShapeT_co = TypeVar("_ShapeT_co", covariant=True, bound=tuple[int, ...])
1616
_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True)
1717

18-
class MaskedRecords(MaskedArray[_ShapeType_co, _DType_co]):
18+
class MaskedRecords(MaskedArray[_ShapeT_co, _DType_co]):
1919
def __new__(
2020
cls,
2121
shape,

numpy/polynomial/_polybase.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ABCPolyBase(Generic[_NameCo], metaclass=abc.ABCMeta):
8686

8787
@overload
8888
def __call__(self, /, arg: _Other) -> _Other: ...
89-
# TODO: Once `_ShapeType@ndarray` is covariant and bounded (see #26081),
89+
# TODO: Once `_ShapeT@ndarray` is covariant and bounded (see #26081),
9090
# additionally include 0-d arrays as input types with scalar return type.
9191
@overload
9292
def __call__(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any
22
import numpy as np
33

4-
# test bounds of _ShapeType_co
4+
# test bounds of _ShapeT_co
55

66
np.ndarray[tuple[str, str], Any] # E: Value of type variable

numpy/typing/tests/data/pass/shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class XYGrid(NamedTuple):
88
x_axis: int
99
y_axis: int
1010

11-
# Test variance of _ShapeType_co
11+
# Test variance of _ShapeT_co
1212
def accepts_2d(a: np.ndarray[tuple[int, int], Any]) -> None:
1313
return None
1414

0 commit comments

Comments
 (0)