Skip to content

Commit 487182a

Browse files
committed
🎨 clean up dtype.__new__ with _numtype.ToDType*
1 parent 97d7262 commit 487182a

File tree

1 file changed

+31
-60
lines changed

1 file changed

+31
-60
lines changed

‎src/numpy-stubs/__init__.pyi

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -353,38 +353,9 @@ from ._typing import (
353353
_ScalarLike_co,
354354
_ShapeLike,
355355
_TD64Like_co,
356-
_VoidDTypeLike,
357356
_nbit_base as _n,
358357
)
359-
from ._typing._char_codes import (
360-
_BoolCodes,
361-
_BytesCodes,
362-
_CLongDoubleCodes,
363-
_Complex64Codes,
364-
_Complex128Codes,
365-
_DT64Codes,
366-
_Float16Codes,
367-
_Float32Codes,
368-
_Float64Codes,
369-
_Int8Codes,
370-
_Int16Codes,
371-
_Int32Codes,
372-
_Int64Codes,
373-
_IntPCodes,
374-
_LongCodes,
375-
_LongDoubleCodes,
376-
_ObjectCodes,
377-
_StrCodes,
378-
_StringCodes,
379-
_TD64Codes,
380-
_UInt8Codes,
381-
_UInt16Codes,
382-
_UInt32Codes,
383-
_UInt64Codes,
384-
_UIntPCodes,
385-
_ULongCodes,
386-
_VoidCodes,
387-
)
358+
from ._typing._char_codes import _LongCodes, _ULongCodes
388359
from .lib import scimath as emath
389360
from .lib._arraypad_impl import pad
390361
from .lib._arraysetops_impl import (
@@ -1172,55 +1143,55 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
11721143
@overload
11731144
def __new__(
11741145
cls,
1175-
dtype: type[bool_ | py_bool | ct.c_bool] | _BoolCodes,
1146+
dtype: _nt.ToDTypeBool,
11761147
align: py_bool = False,
11771148
copy: py_bool = False,
11781149
metadata: dict[str, Any] = ...,
11791150
) -> dtype[bool_]: ...
11801151
@overload
11811152
def __new__(
11821153
cls,
1183-
dtype: type[int8 | ct.c_int8] | _Int8Codes,
1154+
dtype: _nt.ToDTypeInt8,
11841155
align: py_bool = False,
11851156
copy: py_bool = False,
11861157
metadata: dict[str, Any] = ...,
11871158
) -> dtype[int8]: ...
11881159
@overload
11891160
def __new__(
11901161
cls,
1191-
dtype: type[uint8 | ct.c_uint8] | _UInt8Codes,
1162+
dtype: _nt.ToDTypeUInt8,
11921163
align: py_bool = False,
11931164
copy: py_bool = False,
11941165
metadata: dict[str, Any] = ...,
11951166
) -> dtype[uint8]: ...
11961167
@overload
11971168
def __new__(
11981169
cls,
1199-
dtype: type[int16 | ct.c_int16 | ct.c_short] | _Int16Codes,
1170+
dtype: _nt.ToDTypeInt16,
12001171
align: py_bool = False,
12011172
copy: py_bool = False,
12021173
metadata: dict[str, Any] = ...,
12031174
) -> dtype[int16]: ...
12041175
@overload
12051176
def __new__(
12061177
cls,
1207-
dtype: type[uint16 | ct.c_uint16 | ct.c_ushort] | _UInt16Codes,
1178+
dtype: _nt.ToDTypeUInt16,
12081179
align: py_bool = False,
12091180
copy: py_bool = False,
12101181
metadata: dict[str, Any] = ...,
12111182
) -> dtype[uint16]: ...
12121183
@overload
12131184
def __new__(
12141185
cls,
1215-
dtype: type[int32 | ct.c_int32 | ct.c_int] | _Int32Codes,
1186+
dtype: _nt.ToDTypeInt32,
12161187
align: py_bool = False,
12171188
copy: py_bool = False,
12181189
metadata: dict[str, Any] = ...,
12191190
) -> dtype[int32]: ...
12201191
@overload
12211192
def __new__(
12221193
cls,
1223-
dtype: type[uint32 | ct.c_uint32 | ct.c_uint] | _UInt32Codes,
1194+
dtype: _nt.ToDTypeUInt32,
12241195
align: py_bool = False,
12251196
copy: py_bool = False,
12261197
metadata: dict[str, Any] = ...,
@@ -1244,127 +1215,127 @@ class dtype(Generic[_ScalarT_co], metaclass=_DTypeMeta):
12441215
@overload
12451216
def __new__(
12461217
cls,
1247-
dtype: type[int64 | _nt.JustInt | ct.c_int64 | ct.c_longlong | ct.c_ssize_t] | _Int64Codes | _IntPCodes,
1218+
dtype: _nt.ToDTypeInt64,
12481219
align: py_bool = False,
12491220
copy: py_bool = False,
12501221
metadata: dict[str, Any] = ...,
12511222
) -> dtype[int64]: ...
12521223
@overload
12531224
def __new__(
12541225
cls,
1255-
dtype: type[uint64 | ct.c_uint64 | ct.c_ulonglong | ct.c_size_t | ct.c_void_p] | _UInt64Codes | _UIntPCodes,
1226+
dtype: _nt.ToDTypeUInt64,
12561227
align: py_bool = False,
12571228
copy: py_bool = False,
12581229
metadata: dict[str, Any] = ...,
12591230
) -> dtype[uint64]: ...
12601231
@overload
12611232
def __new__(
12621233
cls,
1263-
dtype: type[float16] | _Float16Codes,
1234+
dtype: _nt.ToDTypeFloat16,
12641235
align: py_bool = False,
12651236
copy: py_bool = False,
12661237
metadata: dict[str, Any] = ...,
12671238
) -> dtype[float16]: ...
12681239
@overload
12691240
def __new__(
12701241
cls,
1271-
dtype: type[float32 | ct.c_float] | _Float32Codes,
1242+
dtype: _nt.ToDTypeFloat32,
12721243
align: py_bool = False,
12731244
copy: py_bool = False,
12741245
metadata: dict[str, Any] = ...,
12751246
) -> dtype[float32]: ...
12761247
@overload
12771248
def __new__(
12781249
cls,
1279-
dtype: type[float64 | _nt.JustFloat | ct.c_double] | _Float64Codes | None,
1250+
dtype: _nt.ToDTypeFloat64 | None,
12801251
align: py_bool = False,
12811252
copy: py_bool = False,
12821253
metadata: dict[str, Any] = ...,
12831254
) -> dtype[float64]: ...
12841255
@overload
12851256
def __new__(
12861257
cls,
1287-
dtype: type[longdouble | ct.c_longdouble] | _LongDoubleCodes,
1258+
dtype: _nt.ToDTypeLongDouble,
12881259
align: py_bool = False,
12891260
copy: py_bool = False,
12901261
metadata: dict[str, Any] = ...,
12911262
) -> dtype[longdouble]: ...
12921263
@overload # `complexfloating` string-based representations
12931264
def __new__(
12941265
cls,
1295-
dtype: type[complex64] | _Complex64Codes,
1266+
dtype: _nt.ToDTypeComplex64,
12961267
align: py_bool = False,
12971268
copy: py_bool = False,
12981269
metadata: dict[str, Any] = ...,
12991270
) -> dtype[complex64]: ...
13001271
@overload
13011272
def __new__(
13021273
cls,
1303-
dtype: type[complex128 | _nt.JustComplex] | _Complex128Codes,
1274+
dtype: _nt.ToDTypeComplex128,
13041275
align: py_bool = False,
13051276
copy: py_bool = False,
13061277
metadata: dict[str, Any] = ...,
13071278
) -> dtype[complex128]: ...
13081279
@overload
13091280
def __new__(
13101281
cls,
1311-
dtype: type[clongdouble] | _CLongDoubleCodes,
1282+
dtype: _nt.ToDTypeCLongDouble,
13121283
align: py_bool = False,
13131284
copy: py_bool = False,
13141285
metadata: dict[str, Any] = ...,
13151286
) -> dtype[clongdouble]: ...
13161287
@overload
13171288
def __new__(
13181289
cls,
1319-
dtype: type[bytes_ | _nt.JustBytes | ct.c_char] | _BytesCodes,
1290+
dtype: _nt.ToDTypeObject,
13201291
align: py_bool = False,
13211292
copy: py_bool = False,
13221293
metadata: dict[str, Any] = ...,
1323-
) -> dtype[bytes_]: ...
1294+
) -> dtype[object_]: ...
13241295
@overload
13251296
def __new__(
13261297
cls,
1327-
dtype: type[str_ | _nt.JustStr] | _StrCodes,
1298+
dtype: _nt.ToDTypeBytes,
13281299
align: py_bool = False,
13291300
copy: py_bool = False,
13301301
metadata: dict[str, Any] = ...,
1331-
) -> dtype[str_]: ...
1302+
) -> dtype[bytes_]: ...
13321303
@overload
1333-
def __new__(
1304+
def __new__( # type: ignore[overload-overlap]
13341305
cls,
1335-
dtype: type[void | memoryview] | _VoidDTypeLike | _VoidCodes,
1306+
dtype: _nt.ToDTypeStr,
13361307
align: py_bool = False,
13371308
copy: py_bool = False,
13381309
metadata: dict[str, Any] = ...,
1339-
) -> dtype[void]: ...
1310+
) -> dtype[str_]: ...
13401311
@overload
13411312
def __new__(
13421313
cls,
1343-
dtype: type[datetime64] | _DT64Codes,
1314+
dtype: _nt.ToDTypeVoid,
13441315
align: py_bool = False,
13451316
copy: py_bool = False,
13461317
metadata: dict[str, Any] = ...,
1347-
) -> dtype[datetime64]: ...
1318+
) -> dtype[void]: ...
13481319
@overload
13491320
def __new__(
13501321
cls,
1351-
dtype: type[timedelta64] | _TD64Codes,
1322+
dtype: _nt.ToDTypeDateTime64,
13521323
align: py_bool = False,
13531324
copy: py_bool = False,
13541325
metadata: dict[str, Any] = ...,
1355-
) -> dtype[timedelta64]: ...
1326+
) -> dtype[datetime64]: ...
13561327
@overload
13571328
def __new__(
13581329
cls,
1359-
dtype: type[object_ | _nt.JustObject | _BuiltinObjectLike | ct.py_object[Any]] | _ObjectCodes,
1330+
dtype: _nt.ToDTypeTimeDelta64,
13601331
align: py_bool = False,
13611332
copy: py_bool = False,
13621333
metadata: dict[str, Any] = ...,
1363-
) -> dtype[object_]: ...
1334+
) -> dtype[timedelta64]: ...
13641335
@overload
13651336
def __new__(
13661337
cls,
1367-
dtype: dtypes.StringDType | _StringCodes,
1338+
dtype: _nt.ToDTypeString,
13681339
align: py_bool = False,
13691340
copy: py_bool = False,
13701341
metadata: dict[str, Any] = ...,

0 commit comments

Comments
 (0)