Skip to content

Commit 98fad6b

Browse files
committed
🎨 minor dtype simplifications and reformatting
1 parent bbcb0da commit 98fad6b

File tree

1 file changed

+39
-177
lines changed

1 file changed

+39
-177
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 39 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,7 @@ from typing import (
3131
overload,
3232
type_check_only,
3333
)
34-
from typing_extensions import (
35-
Buffer,
36-
CapsuleType,
37-
Protocol,
38-
TypeVar,
39-
deprecated,
40-
override,
41-
)
34+
from typing_extensions import Buffer, CapsuleType, Protocol, TypeVar, deprecated, override
4235

4336
import _numtype as _nt
4437

@@ -360,7 +353,6 @@ from ._typing import (
360353
_ShapeLike,
361354
_TD64Like_co,
362355
)
363-
from ._typing._char_codes import _LongCodes, _ULongCodes
364356
from .lib import scimath as emath
365357
from .lib._arraypad_impl import pad
366358
from .lib._arraysetops_impl import (
@@ -654,10 +646,7 @@ _NumberItemT = TypeVar("_NumberItemT", bound=complex)
654646
_NumberItemT_co = TypeVar("_NumberItemT_co", bound=complex, default=Any, covariant=True)
655647
_InexactItemT_co = TypeVar("_InexactItemT_co", bound=complex, default=Any, covariant=True)
656648
_FlexItemT_co = TypeVar(
657-
"_FlexItemT_co",
658-
bound=bytes | str | tuple[object, ...],
659-
default=bytes | str | tuple[Any, ...],
660-
covariant=True,
649+
"_FlexItemT_co", bound=bytes | str | tuple[object, ...], default=bytes | str | tuple[Any, ...], covariant=True
661650
)
662651
_CharacterItemT_co = TypeVar("_CharacterItemT_co", bound=bytes | str, default=bytes | str, covariant=True)
663652
_TD64ItemT_co = TypeVar(
@@ -1191,219 +1180,111 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
11911180
#
11921181
@overload
11931182
def __new__(
1194-
cls,
1195-
dtype: _nt.ToDTypeBool,
1196-
align: py_bool = False,
1197-
copy: py_bool = False,
1198-
metadata: _MetaData = ...,
1183+
cls, dtype: _nt.ToDTypeBool, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
11991184
) -> dtypes.BoolDType: ...
12001185
@overload
12011186
def __new__(
1202-
cls,
1203-
dtype: _nt.ToDTypeInt8,
1204-
align: py_bool = False,
1205-
copy: py_bool = False,
1206-
metadata: _MetaData = ...,
1187+
cls, dtype: _nt.ToDTypeInt8, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12071188
) -> dtypes.Int8DType: ...
12081189
@overload
12091190
def __new__(
1210-
cls,
1211-
dtype: _nt.ToDTypeUInt8,
1212-
align: py_bool = False,
1213-
copy: py_bool = False,
1214-
metadata: _MetaData = ...,
1215-
) -> dtypes.UByteDType: ...
1191+
cls, dtype: _nt.ToDTypeUInt8, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
1192+
) -> dtypes.UInt8DType: ...
12161193
@overload
12171194
def __new__(
1218-
cls,
1219-
dtype: _nt.ToDTypeInt16,
1220-
align: py_bool = False,
1221-
copy: py_bool = False,
1222-
metadata: _MetaData = ...,
1195+
cls, dtype: _nt.ToDTypeInt16, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12231196
) -> dtypes.Int16DType: ...
12241197
@overload
12251198
def __new__(
1226-
cls,
1227-
dtype: _nt.ToDTypeUInt16,
1228-
align: py_bool = False,
1229-
copy: py_bool = False,
1230-
metadata: _MetaData = ...,
1199+
cls, dtype: _nt.ToDTypeUInt16, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12311200
) -> dtypes.UInt16DType: ...
12321201
@overload
12331202
def __new__(
1234-
cls,
1235-
dtype: _nt.ToDTypeInt32,
1236-
align: py_bool = False,
1237-
copy: py_bool = False,
1238-
metadata: _MetaData = ...,
1203+
cls, dtype: _nt.ToDTypeInt32, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12391204
) -> dtypes.Int32DType: ...
12401205
@overload
12411206
def __new__(
1242-
cls,
1243-
dtype: _nt.ToDTypeUInt32,
1244-
align: py_bool = False,
1245-
copy: py_bool = False,
1246-
metadata: _MetaData = ...,
1207+
cls, dtype: _nt.ToDTypeUInt32, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12471208
) -> dtypes.UInt32DType: ...
12481209
@overload
12491210
def __new__(
1250-
cls,
1251-
dtype: type[ct.c_long] | _LongCodes,
1252-
align: py_bool = False,
1253-
copy: py_bool = False,
1254-
metadata: _MetaData = ...,
1211+
cls, dtype: _nt.ToDTypeLong, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12551212
) -> dtypes.LongDType: ...
12561213
@overload
12571214
def __new__(
1258-
cls,
1259-
dtype: type[ct.c_ulong] | _ULongCodes,
1260-
align: py_bool = False,
1261-
copy: py_bool = False,
1262-
metadata: _MetaData = ...,
1215+
cls, dtype: _nt.ToDTypeULong, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12631216
) -> dtypes.ULongDType: ...
12641217
@overload
12651218
def __new__(
1266-
cls,
1267-
dtype: _nt.ToDTypeInt64,
1268-
align: py_bool = False,
1269-
copy: py_bool = False,
1270-
metadata: _MetaData = ...,
1219+
cls, dtype: _nt.ToDTypeInt64, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12711220
) -> dtypes.Int64DType: ...
12721221
@overload
12731222
def __new__(
1274-
cls,
1275-
dtype: _nt.ToDTypeUInt64,
1276-
align: py_bool = False,
1277-
copy: py_bool = False,
1278-
metadata: _MetaData = ...,
1223+
cls, dtype: _nt.ToDTypeUInt64, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12791224
) -> dtypes.UInt64DType: ...
12801225
@overload
12811226
def __new__(
1282-
cls,
1283-
dtype: _nt.ToDTypeFloat16,
1284-
align: py_bool = False,
1285-
copy: py_bool = False,
1286-
metadata: _MetaData = ...,
1227+
cls, dtype: _nt.ToDTypeFloat16, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12871228
) -> dtypes.Float16DType: ...
12881229
@overload
12891230
def __new__(
1290-
cls,
1291-
dtype: _nt.ToDTypeFloat32,
1292-
align: py_bool = False,
1293-
copy: py_bool = False,
1294-
metadata: _MetaData = ...,
1231+
cls, dtype: _nt.ToDTypeFloat32, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
12951232
) -> dtypes.Float32DType: ...
12961233
@overload
12971234
def __new__(
1298-
cls,
1299-
dtype: _nt.ToDTypeFloat64 | None,
1300-
align: py_bool = False,
1301-
copy: py_bool = False,
1302-
metadata: _MetaData = ...,
1235+
cls, dtype: _nt.ToDTypeFloat64 | None, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13031236
) -> dtypes.Float64DType: ...
13041237
@overload
13051238
def __new__(
1306-
cls,
1307-
dtype: _nt.ToDTypeLongDouble,
1308-
align: py_bool = False,
1309-
copy: py_bool = False,
1310-
metadata: _MetaData = ...,
1239+
cls, dtype: _nt.ToDTypeLongDouble, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13111240
) -> dtypes.LongDoubleDType: ...
13121241
@overload
13131242
def __new__(
1314-
cls,
1315-
dtype: _nt.ToDTypeComplex64,
1316-
align: py_bool = False,
1317-
copy: py_bool = False,
1318-
metadata: _MetaData = ...,
1243+
cls, dtype: _nt.ToDTypeComplex64, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13191244
) -> dtypes.Complex64DType: ...
13201245
@overload
13211246
def __new__(
1322-
cls,
1323-
dtype: _nt.ToDTypeComplex128,
1324-
align: py_bool = False,
1325-
copy: py_bool = False,
1326-
metadata: _MetaData = ...,
1247+
cls, dtype: _nt.ToDTypeComplex128, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13271248
) -> dtypes.Complex128DType: ...
13281249
@overload
13291250
def __new__(
1330-
cls,
1331-
dtype: _nt.ToDTypeCLongDouble,
1332-
align: py_bool = False,
1333-
copy: py_bool = False,
1334-
metadata: _MetaData = ...,
1251+
cls, dtype: _nt.ToDTypeCLongDouble, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13351252
) -> dtypes.CLongDoubleDType: ...
13361253
@overload
13371254
def __new__(
1338-
cls,
1339-
dtype: _nt.ToDTypeObject,
1340-
align: py_bool = False,
1341-
copy: py_bool = False,
1342-
metadata: _MetaData = ...,
1255+
cls, dtype: _nt.ToDTypeObject, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13431256
) -> dtypes.ObjectDType: ...
13441257
@overload
13451258
def __new__(
1346-
cls,
1347-
dtype: _nt.ToDTypeBytes,
1348-
align: py_bool = False,
1349-
copy: py_bool = False,
1350-
metadata: _MetaData = ...,
1259+
cls, dtype: _nt.ToDTypeBytes, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13511260
) -> dtypes.BytesDType: ...
13521261
@overload
13531262
def __new__( # type: ignore[overload-overlap]
1354-
cls,
1355-
dtype: _nt.ToDTypeStr,
1356-
align: py_bool = False,
1357-
copy: py_bool = False,
1358-
metadata: _MetaData = ...,
1263+
cls, dtype: _nt.ToDTypeStr, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13591264
) -> dtypes.StrDType: ...
13601265
@overload
13611266
def __new__(
1362-
cls,
1363-
dtype: _nt.ToDTypeVoid,
1364-
align: py_bool = False,
1365-
copy: py_bool = False,
1366-
metadata: _MetaData = ...,
1267+
cls, dtype: _nt.ToDTypeVoid, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13671268
) -> dtypes.VoidDType: ...
13681269
@overload
13691270
def __new__(
1370-
cls,
1371-
dtype: _nt.ToDTypeDateTime64,
1372-
align: py_bool = False,
1373-
copy: py_bool = False,
1374-
metadata: _MetaData = ...,
1271+
cls, dtype: _nt.ToDTypeDateTime64, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13751272
) -> dtypes.DateTime64DType: ...
13761273
@overload
13771274
def __new__(
1378-
cls,
1379-
dtype: _nt.ToDTypeTimeDelta64,
1380-
align: py_bool = False,
1381-
copy: py_bool = False,
1382-
metadata: _MetaData = ...,
1275+
cls, dtype: _nt.ToDTypeTimeDelta64, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13831276
) -> dtypes.TimeDelta64DType: ...
13841277
@overload
13851278
def __new__(
1386-
cls,
1387-
dtype: _nt.ToDTypeString,
1388-
align: py_bool = False,
1389-
copy: py_bool = False,
1390-
metadata: _MetaData = ...,
1279+
cls, dtype: _nt.ToDTypeString, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13911280
) -> dtypes.StringDType: ...
13921281
@overload
13931282
def __new__(
1394-
cls,
1395-
dtype: _DTypeLike[_ScalarT_co],
1396-
align: py_bool = False,
1397-
copy: py_bool = False,
1398-
metadata: _MetaData = ...,
1283+
cls, dtype: _DTypeLike[_ScalarT_co], align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
13991284
) -> Self: ...
14001285
@overload
14011286
def __new__(
1402-
cls,
1403-
dtype: DTypeLike,
1404-
align: py_bool = False,
1405-
copy: py_bool = False,
1406-
metadata: _MetaData = ...,
1287+
cls, dtype: DTypeLike, align: py_bool = False, copy: py_bool = False, metadata: _MetaData = ...
14071288
) -> dtype: ...
14081289

14091290
#
@@ -1544,7 +1425,7 @@ class _ArrayOrScalarCommon:
15441425
keepdims: py_bool = False,
15451426
initial: _NumberLike_co = ...,
15461427
where: _nt.ToBool_nd = True,
1547-
) -> Any: ...
1428+
) -> Incomplete: ...
15481429
@overload
15491430
def max(
15501431
self,
@@ -1571,7 +1452,7 @@ class _ArrayOrScalarCommon:
15711452
@overload # axis=None (default), out=None (default), keepdims=False (default)
15721453
def argmax(self, /, axis: None = None, out: None = None, *, keepdims: L[False] = False) -> intp: ...
15731454
@overload # axis=index, out=None (default)
1574-
def argmax(self, /, axis: CanIndex, out: None = None, *, keepdims: py_bool = False) -> Any: ...
1455+
def argmax(self, /, axis: CanIndex, out: None = None, *, keepdims: py_bool = False) -> Incomplete: ...
15751456
@overload # axis=index, out=ndarray
15761457
def argmax(self, /, axis: CanIndex | None, out: _ArrayT, *, keepdims: py_bool = False) -> _ArrayT: ...
15771458
@overload
@@ -1587,7 +1468,7 @@ class _ArrayOrScalarCommon:
15871468
keepdims: py_bool = False,
15881469
initial: _NumberLike_co = ...,
15891470
where: _nt.ToBool_nd = True,
1590-
) -> Any: ...
1471+
) -> Incomplete: ...
15911472
@overload
15921473
def min(
15931474
self,
@@ -1614,7 +1495,7 @@ class _ArrayOrScalarCommon:
16141495
@overload # axis=None (default), out=None (default), keepdims=False (default)
16151496
def argmin(self, /, axis: None = None, out: None = None, *, keepdims: L[False] = False) -> intp: ...
16161497
@overload # axis=index, out=None (default)
1617-
def argmin(self, /, axis: CanIndex, out: None = None, *, keepdims: py_bool = False) -> Any: ...
1498+
def argmin(self, /, axis: CanIndex, out: None = None, *, keepdims: py_bool = False) -> Incomplete: ...
16181499
@overload # axis=index, out=ndarray
16191500
def argmin(self, /, axis: CanIndex | None, out: _ArrayT, *, keepdims: py_bool = False) -> _ArrayT: ...
16201501
@overload
@@ -1637,12 +1518,7 @@ class _ArrayOrScalarCommon:
16371518
# TODO: Annotate kwargs with an unpacked `TypedDict`
16381519
@overload # out: None (default)
16391520
def clip(
1640-
self,
1641-
/,
1642-
min: ArrayLike,
1643-
max: ArrayLike | None = None,
1644-
out: None = None,
1645-
**kwargs: object,
1521+
self, /, min: ArrayLike, max: ArrayLike | None = None, out: None = None, **kwargs: object
16461522
) -> _nt.Array: ...
16471523
@overload
16481524
def clip(self, /, min: None, max: ArrayLike, out: None = None, **kwargs: object) -> _nt.Array: ...
@@ -1659,13 +1535,7 @@ class _ArrayOrScalarCommon:
16591535

16601536
#
16611537
@overload
1662-
def compress(
1663-
self,
1664-
/,
1665-
condition: _nt.CoInteger_nd,
1666-
axis: CanIndex | None = None,
1667-
out: None = None,
1668-
) -> _nt.Array: ...
1538+
def compress(self, /, condition: _nt.CoInteger_nd, axis: CanIndex | None = None, out: None = None) -> _nt.Array: ...
16691539
@overload
16701540
def compress(self, /, condition: _nt.CoInteger_nd, axis: CanIndex | None, out: _ArrayT) -> _ArrayT: ...
16711541
@overload
@@ -1674,11 +1544,7 @@ class _ArrayOrScalarCommon:
16741544
#
16751545
@overload # out: None (default)
16761546
def cumprod(
1677-
self,
1678-
/,
1679-
axis: CanIndex | None = None,
1680-
dtype: DTypeLike | None = None,
1681-
out: None = None,
1547+
self, /, axis: CanIndex | None = None, dtype: DTypeLike | None = None, out: None = None
16821548
) -> _nt.Array: ...
16831549
@overload # out: ndarray
16841550
def cumprod(self, /, axis: CanIndex | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
@@ -1725,11 +1591,7 @@ class _ArrayOrScalarCommon:
17251591
#
17261592
@overload # out: None (default)
17271593
def cumsum(
1728-
self,
1729-
/,
1730-
axis: CanIndex | None = None,
1731-
dtype: DTypeLike | None = None,
1732-
out: None = None,
1594+
self, /, axis: CanIndex | None = None, dtype: DTypeLike | None = None, out: None = None
17331595
) -> _nt.Array: ...
17341596
@overload # out: ndarray
17351597
def cumsum(self, /, axis: CanIndex | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
@@ -3446,7 +3308,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
34463308
casting: _CastingKind = "unsafe",
34473309
subok: py_bool = True,
34483310
copy: py_bool | _CopyMode = True,
3449-
) -> ndarray[_ShapeT_co, dtype]: ...
3311+
) -> ndarray[_ShapeT_co]: ...
34503312

34513313
# the special casings work around the lack of higher-kinded typing (HKT) support in Python
34523314
@overload # ()

0 commit comments

Comments
 (0)