Skip to content

Commit 8a8579a

Browse files
TYP: replace _DType with _DTypeT (numpy#28684)
Co-authored-by: Joren Hammudoglu <[email protected]>
1 parent 8f11c7b commit 8a8579a

File tree

9 files changed

+191
-191
lines changed

9 files changed

+191
-191
lines changed

numpy/__init__.pyi

Lines changed: 139 additions & 139 deletions
Large diffs are not rendered by default.

numpy/_core/defchararray.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ __all__ = [
9191

9292
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
9393
_SCT = TypeVar("_SCT", bound=np.character)
94-
_CharDType_co = TypeVar("_CharDType_co", bound=dtype[np.character], covariant=True)
94+
_CharDTypeT_co = TypeVar("_CharDTypeT_co", bound=dtype[np.character], covariant=True)
9595
_CharArray: TypeAlias = chararray[tuple[int, ...], dtype[_SCT]]
9696

9797
_StringDTypeArray: TypeAlias = np.ndarray[_Shape, np.dtypes.StringDType]
9898
_StringDTypeSupportsArray: TypeAlias = _SupportsArray[np.dtypes.StringDType]
9999
_StringDTypeOrUnicodeArray: TypeAlias = np.ndarray[_Shape, np.dtype[np.str_]] | np.ndarray[_Shape, np.dtypes.StringDType]
100100

101-
class chararray(ndarray[_ShapeT_co, _CharDType_co]):
101+
class chararray(ndarray[_ShapeT_co, _CharDTypeT_co]):
102102
@overload
103103
def __new__(
104104
subtype,
@@ -123,9 +123,9 @@ class chararray(ndarray[_ShapeT_co, _CharDType_co]):
123123
) -> chararray[_Shape, dtype[str_]]: ...
124124

125125
def __array_finalize__(self, obj: object) -> None: ...
126-
def __mul__(self, other: i_co) -> chararray[_Shape, _CharDType_co]: ...
127-
def __rmul__(self, other: i_co) -> chararray[_Shape, _CharDType_co]: ...
128-
def __mod__(self, i: Any) -> chararray[_Shape, _CharDType_co]: ...
126+
def __mul__(self, other: i_co) -> chararray[_Shape, _CharDTypeT_co]: ...
127+
def __rmul__(self, other: i_co) -> chararray[_Shape, _CharDTypeT_co]: ...
128+
def __mod__(self, i: Any) -> chararray[_Shape, _CharDTypeT_co]: ...
129129

130130
@overload
131131
def __eq__(
@@ -273,7 +273,7 @@ class chararray(ndarray[_ShapeT_co, _CharDType_co]):
273273
def expandtabs(
274274
self,
275275
tabsize: i_co = ...,
276-
) -> chararray[_Shape, _CharDType_co]: ...
276+
) -> chararray[_Shape, _CharDTypeT_co]: ...
277277

278278
@overload
279279
def find(
@@ -498,12 +498,12 @@ class chararray(ndarray[_ShapeT_co, _CharDType_co]):
498498
deletechars: None | S_co = ...,
499499
) -> _CharArray[bytes_]: ...
500500

501-
def zfill(self, width: i_co) -> chararray[_Shape, _CharDType_co]: ...
502-
def capitalize(self) -> chararray[_ShapeT_co, _CharDType_co]: ...
503-
def title(self) -> chararray[_ShapeT_co, _CharDType_co]: ...
504-
def swapcase(self) -> chararray[_ShapeT_co, _CharDType_co]: ...
505-
def lower(self) -> chararray[_ShapeT_co, _CharDType_co]: ...
506-
def upper(self) -> chararray[_ShapeT_co, _CharDType_co]: ...
501+
def zfill(self, width: i_co) -> chararray[_Shape, _CharDTypeT_co]: ...
502+
def capitalize(self) -> chararray[_ShapeT_co, _CharDTypeT_co]: ...
503+
def title(self) -> chararray[_ShapeT_co, _CharDTypeT_co]: ...
504+
def swapcase(self) -> chararray[_ShapeT_co, _CharDTypeT_co]: ...
505+
def lower(self) -> chararray[_ShapeT_co, _CharDTypeT_co]: ...
506+
def upper(self) -> chararray[_ShapeT_co, _CharDTypeT_co]: ...
507507
def isalnum(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ...
508508
def isalpha(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ...
509509
def isdigit(self) -> ndarray[_ShapeT_co, dtype[np.bool]]: ...

numpy/_core/multiarray.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ __all__ = [
193193
]
194194

195195
_SCT = TypeVar("_SCT", bound=generic)
196-
_DType = TypeVar("_DType", bound=np.dtype[Any])
196+
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any])
197197
_ArrayT = TypeVar("_ArrayT", bound=ndarray[Any, Any])
198198
_ArrayT_co = TypeVar(
199199
"_ArrayT_co",
@@ -260,10 +260,10 @@ class _ConstructorEmpty(Protocol):
260260
self,
261261
/,
262262
shape: SupportsIndex,
263-
dtype: _DType | _SupportsDType[_DType],
263+
dtype: _DTypeT | _SupportsDType[_DTypeT],
264264
order: _OrderCF = ...,
265265
**kwargs: Unpack[_KwargsEmpty],
266-
) -> ndarray[tuple[int], _DType]: ...
266+
) -> ndarray[tuple[int], _DTypeT]: ...
267267
@overload
268268
def __call__(
269269
self,
@@ -298,10 +298,10 @@ class _ConstructorEmpty(Protocol):
298298
self,
299299
/,
300300
shape: _AnyShapeT,
301-
dtype: _DType | _SupportsDType[_DType],
301+
dtype: _DTypeT | _SupportsDType[_DTypeT],
302302
order: _OrderCF = ...,
303303
**kwargs: Unpack[_KwargsEmpty],
304-
) -> ndarray[_AnyShapeT, _DType]: ...
304+
) -> ndarray[_AnyShapeT, _DTypeT]: ...
305305
@overload
306306
def __call__(
307307
self,
@@ -334,10 +334,10 @@ class _ConstructorEmpty(Protocol):
334334
def __call__(
335335
self, /,
336336
shape: _ShapeLike,
337-
dtype: _DType | _SupportsDType[_DType],
337+
dtype: _DTypeT | _SupportsDType[_DTypeT],
338338
order: _OrderCF = ...,
339339
**kwargs: Unpack[_KwargsEmpty],
340-
) -> ndarray[Any, _DType]: ...
340+
) -> ndarray[Any, _DTypeT]: ...
341341
@overload
342342
def __call__(
343343
self, /,
@@ -382,7 +382,7 @@ set_datetimeparse_function: Final[Callable[..., object]]
382382
def get_handler_name(a: NDArray[Any] = ..., /) -> str | None: ...
383383
def get_handler_version(a: NDArray[Any] = ..., /) -> int | None: ...
384384
def format_longfloat(x: np.longdouble, precision: int) -> str: ...
385-
def scalar(dtype: _DType, object: bytes | object = ...) -> ndarray[tuple[()], _DType]: ...
385+
def scalar(dtype: _DTypeT, object: bytes | object = ...) -> ndarray[tuple[()], _DTypeT]: ...
386386
def set_typeDict(dict_: dict[str, np.dtype[Any]], /) -> None: ...
387387
typeinfo: Final[dict[str, np.dtype[np.generic]]]
388388

numpy/_core/numeric.pyi

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ __all__ = [
189189

190190
_T = TypeVar("_T")
191191
_SCT = TypeVar("_SCT", bound=generic)
192-
_DType = TypeVar("_DType", bound=np.dtype[Any])
192+
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[Any])
193193
_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any])
194194
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
195195

@@ -293,10 +293,10 @@ def full(
293293
def full(
294294
shape: SupportsIndex,
295295
fill_value: Any,
296-
dtype: _DType | _SupportsDType[_DType],
296+
dtype: _DTypeT | _SupportsDType[_DTypeT],
297297
order: _OrderCF = ...,
298298
**kwargs: Unpack[_KwargsEmpty],
299-
) -> np.ndarray[tuple[int], _DType]: ...
299+
) -> np.ndarray[tuple[int], _DTypeT]: ...
300300
@overload
301301
def full(
302302
shape: SupportsIndex,
@@ -326,10 +326,10 @@ def full(
326326
def full(
327327
shape: _AnyShapeT,
328328
fill_value: Any,
329-
dtype: _DType | _SupportsDType[_DType],
329+
dtype: _DTypeT | _SupportsDType[_DTypeT],
330330
order: _OrderCF = ...,
331331
**kwargs: Unpack[_KwargsEmpty],
332-
) -> np.ndarray[_AnyShapeT, _DType]: ...
332+
) -> np.ndarray[_AnyShapeT, _DTypeT]: ...
333333
@overload
334334
def full(
335335
shape: _AnyShapeT,
@@ -359,10 +359,10 @@ def full(
359359
def full(
360360
shape: _ShapeLike,
361361
fill_value: Any,
362-
dtype: _DType | _SupportsDType[_DType],
362+
dtype: _DTypeT | _SupportsDType[_DTypeT],
363363
order: _OrderCF = ...,
364364
**kwargs: Unpack[_KwargsEmpty],
365-
) -> np.ndarray[Any, _DType]: ...
365+
) -> np.ndarray[Any, _DTypeT]: ...
366366
@overload
367367
def full(
368368
shape: _ShapeLike,

numpy/_typing/_array_like.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
_T = TypeVar("_T")
2121
_SCT = TypeVar("_SCT", bound=np.generic)
2222
_SCT_co = TypeVar("_SCT_co", bound=np.generic, covariant=True)
23-
_DType = TypeVar("_DType", bound=dtype[Any])
24-
_DType_co = TypeVar("_DType_co", covariant=True, bound=dtype[Any])
23+
_DTypeT = TypeVar("_DTypeT", bound=dtype[Any])
24+
_DTypeT_co = TypeVar("_DTypeT_co", covariant=True, bound=dtype[Any])
2525

2626
NDArray: TypeAlias = np.ndarray[_Shape, dtype[_SCT_co]]
2727

@@ -31,8 +31,8 @@
3131
# Concrete implementations of the protocol are responsible for adding
3232
# any and all remaining overloads
3333
@runtime_checkable
34-
class _SupportsArray(Protocol[_DType_co]):
35-
def __array__(self) -> np.ndarray[Any, _DType_co]: ...
34+
class _SupportsArray(Protocol[_DTypeT_co]):
35+
def __array__(self) -> np.ndarray[Any, _DTypeT_co]: ...
3636

3737

3838
@runtime_checkable
@@ -66,8 +66,8 @@ def __array_function__(
6666
# One representing types that can be parametrized w.r.t. `np.dtype`
6767
# and another one for the rest
6868
_DualArrayLike: TypeAlias = (
69-
_SupportsArray[_DType]
70-
| _NestedSequence[_SupportsArray[_DType]]
69+
_SupportsArray[_DTypeT]
70+
| _NestedSequence[_SupportsArray[_DTypeT]]
7171
| _T
7272
| _NestedSequence[_T]
7373
)

numpy/_typing/_dtype_like.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727

2828
_SCT = TypeVar("_SCT", bound=np.generic)
29-
_DType_co = TypeVar("_DType_co", covariant=True, bound=np.dtype[Any])
29+
_DTypeT_co = TypeVar("_DTypeT_co", covariant=True, bound=np.dtype[Any])
3030

3131
_DTypeLikeNested: TypeAlias = Any # TODO: wait for support for recursive types
3232

@@ -49,9 +49,9 @@ class _DTypeDict(_DTypeDictBase, total=False):
4949

5050
# A protocol for anything with the dtype attribute
5151
@runtime_checkable
52-
class _SupportsDType(Protocol[_DType_co]):
52+
class _SupportsDType(Protocol[_DTypeT_co]):
5353
@property
54-
def dtype(self) -> _DType_co: ...
54+
def dtype(self) -> _DTypeT_co: ...
5555

5656

5757
# A subset of `npt.DTypeLike` that can be parametrized w.r.t. `np.generic`

numpy/ctypeslib/_ctypeslib.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ from numpy._typing import (
6969
__all__ = ["load_library", "ndpointer", "c_intp", "as_ctypes", "as_array", "as_ctypes_type"]
7070

7171
# TODO: Add a proper `_Shape` bound once we've got variadic typevars
72-
_DType = TypeVar("_DType", bound=dtype[Any])
73-
_DTypeOptional = TypeVar("_DTypeOptional", bound=None | dtype[Any])
72+
_DTypeT = TypeVar("_DTypeT", bound=dtype[Any])
73+
_DTypeOptionalT = TypeVar("_DTypeOptionalT", bound=None | dtype[Any])
7474
_SCT = TypeVar("_SCT", bound=generic)
7575

7676
_FlagsKind: TypeAlias = L[
@@ -83,10 +83,10 @@ _FlagsKind: TypeAlias = L[
8383
]
8484

8585
# TODO: Add a shape typevar once we have variadic typevars (PEP 646)
86-
class _ndptr(ctypes.c_void_p, Generic[_DTypeOptional]):
86+
class _ndptr(ctypes.c_void_p, Generic[_DTypeOptionalT]):
8787
# In practice these 4 classvars are defined in the dynamic class
8888
# returned by `ndpointer`
89-
_dtype_: ClassVar[_DTypeOptional]
89+
_dtype_: ClassVar[_DTypeOptionalT]
9090
_shape_: ClassVar[None]
9191
_ndim_: ClassVar[None | int]
9292
_flags_: ClassVar[None | list[_FlagsKind]]
@@ -96,13 +96,13 @@ class _ndptr(ctypes.c_void_p, Generic[_DTypeOptional]):
9696
def from_param(cls: type[_ndptr[None]], obj: NDArray[Any]) -> _ctypes[Any]: ...
9797
@overload
9898
@classmethod
99-
def from_param(cls: type[_ndptr[_DType]], obj: ndarray[Any, _DType]) -> _ctypes[Any]: ...
99+
def from_param(cls: type[_ndptr[_DTypeT]], obj: ndarray[Any, _DTypeT]) -> _ctypes[Any]: ...
100100

101-
class _concrete_ndptr(_ndptr[_DType]):
102-
_dtype_: ClassVar[_DType]
101+
class _concrete_ndptr(_ndptr[_DTypeT]):
102+
_dtype_: ClassVar[_DTypeT]
103103
_shape_: ClassVar[tuple[int, ...]]
104104
@property
105-
def contents(self) -> ndarray[_Shape, _DType]: ...
105+
def contents(self) -> ndarray[_Shape, _DTypeT]: ...
106106

107107
def load_library(libname: StrOrBytesPath, loader_path: StrOrBytesPath) -> ctypes.CDLL: ...
108108

numpy/ma/core.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ __all__ = [
219219

220220
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
221221
_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], covariant=True)
222-
_DType = TypeVar("_DType", bound=dtype[Any])
223-
_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True)
222+
_DTypeT = TypeVar("_DTypeT", bound=dtype[Any])
223+
_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype[Any], covariant=True)
224224
_ArrayT = TypeVar("_ArrayT", bound=ndarray[Any, Any])
225225
_SCT = TypeVar("_SCT", bound=generic)
226226
# A subset of `MaskedArray` that can be parametrized w.r.t. `np.generic`
@@ -371,7 +371,7 @@ class MaskedIterator:
371371
def __setitem__(self, index, value): ...
372372
def __next__(self): ...
373373

374-
class MaskedArray(ndarray[_ShapeT_co, _DType_co]):
374+
class MaskedArray(ndarray[_ShapeT_co, _DTypeT_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): ...
@@ -380,9 +380,9 @@ class MaskedArray(ndarray[_ShapeT_co, _DType_co]):
380380
def __getitem__(self, indx): ...
381381
def __setitem__(self, indx, value): ...
382382
@property
383-
def dtype(self) -> _DType_co: ...
383+
def dtype(self) -> _DTypeT_co: ...
384384
@dtype.setter
385-
def dtype(self: MaskedArray[Any, _DType], dtype: _DType, /) -> None: ...
385+
def dtype(self: MaskedArray[Any, _DTypeT], dtype: _DTypeT, /) -> None: ...
386386
@property
387387
def shape(self) -> _ShapeT_co: ...
388388
@shape.setter
@@ -745,7 +745,7 @@ class MaskedArray(ndarray[_ShapeT_co, _DType_co]):
745745
def __reduce__(self): ...
746746
def __deepcopy__(self, memo=...): ...
747747

748-
class mvoid(MaskedArray[_ShapeT_co, _DType_co]):
748+
class mvoid(MaskedArray[_ShapeT_co, _DTypeT_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
@@ -13,9 +13,9 @@ __all__ = [
1313
]
1414

1515
_ShapeT_co = TypeVar("_ShapeT_co", covariant=True, bound=tuple[int, ...])
16-
_DType_co = TypeVar("_DType_co", bound=dtype[Any], covariant=True)
16+
_DTypeT_co = TypeVar("_DTypeT_co", bound=dtype[Any], covariant=True)
1717

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

0 commit comments

Comments
 (0)