1
- from typing import (
2
- Any ,
3
- Final ,
4
- Generic ,
5
- Literal as L ,
6
- NoReturn ,
7
- TypeAlias ,
8
- final ,
9
- type_check_only ,
10
- )
1
+ # ruff: noqa: ANN401
2
+ from types import MemberDescriptorType
3
+ from typing import Any , ClassVar , Generic , NoReturn , TypeAlias , final , type_check_only
4
+ from typing import Literal as L
5
+
11
6
from typing_extensions import LiteralString , Self , TypeVar
12
7
13
8
import numpy as np
14
9
15
- __all__ = [
10
+ __all__ = [ # noqa: RUF022
16
11
'BoolDType' ,
17
12
'Int8DType' ,
18
13
'ByteDType' ,
@@ -53,7 +48,7 @@ __all__ = [
53
48
_SCT_co = TypeVar ("_SCT_co" , bound = np .generic , covariant = True )
54
49
55
50
@type_check_only
56
- class _SimpleDType (Generic [_SCT_co ], np . dtype [_SCT_co ]): # type: ignore[misc]
51
+ class _SimpleDType (np . dtype [_SCT_co ], Generic [_SCT_co ]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues ]
57
52
names : None # pyright: ignore[reportIncompatibleVariableOverride]
58
53
def __new__ (cls , / ) -> Self : ...
59
54
def __getitem__ (self , key : Any , / ) -> NoReturn : ...
@@ -73,7 +68,7 @@ class _SimpleDType(Generic[_SCT_co], np.dtype[_SCT_co]): # type: ignore[misc]
73
68
def subdtype (self ) -> None : ...
74
69
75
70
@type_check_only
76
- class _LiteralDType (Generic [_SCT_co ], _SimpleDType [_SCT_co ]): # type: ignore[misc]
71
+ class _LiteralDType (_SimpleDType [_SCT_co ], Generic [_SCT_co ]): # type: ignore[misc]
77
72
@property
78
73
def flags (self ) -> L [0 ]: ...
79
74
@property
@@ -234,10 +229,11 @@ class UInt64DType( # type: ignore[misc]
234
229
def str (self ) -> L ["<u8" , ">u8" ]: ...
235
230
236
231
# Standard C-named version/alias:
237
- ByteDType : Final = Int8DType
238
- UByteDType : Final = UInt8DType
239
- ShortDType : Final = Int16DType
240
- UShortDType : Final = UInt16DType
232
+ # NOTE: Don't make these `Final`: it will break stubtest
233
+ ByteDType = Int8DType
234
+ UByteDType = UInt8DType
235
+ ShortDType = Int16DType
236
+ UShortDType = UInt16DType
241
237
242
238
@final
243
239
class IntDType ( # type: ignore[misc]
@@ -419,11 +415,11 @@ class ObjectDType( # type: ignore[misc]
419
415
420
416
@final
421
417
class BytesDType ( # type: ignore[misc]
422
- Generic [_ItemSize_co ],
423
418
_TypeCodes [L ["S" ], L ["S" ], L [18 ]],
424
419
_NoOrder ,
425
420
_NBit [L [1 ], _ItemSize_co ],
426
421
_SimpleDType [np .bytes_ ],
422
+ Generic [_ItemSize_co ],
427
423
):
428
424
def __new__ (cls , size : _ItemSize_co , / ) -> BytesDType [_ItemSize_co ]: ...
429
425
@property
@@ -435,11 +431,11 @@ class BytesDType( # type: ignore[misc]
435
431
436
432
@final
437
433
class StrDType ( # type: ignore[misc]
438
- Generic [_ItemSize_co ],
439
434
_TypeCodes [L ["U" ], L ["U" ], L [19 ]],
440
435
_NativeOrder ,
441
436
_NBit [L [4 ], _ItemSize_co ],
442
437
_SimpleDType [np .str_ ],
438
+ Generic [_ItemSize_co ],
443
439
):
444
440
def __new__ (cls , size : _ItemSize_co , / ) -> StrDType [_ItemSize_co ]: ...
445
441
@property
@@ -451,11 +447,11 @@ class StrDType( # type: ignore[misc]
451
447
452
448
@final
453
449
class VoidDType ( # type: ignore[misc]
454
- Generic [_ItemSize_co ],
455
450
_TypeCodes [L ["V" ], L ["V" ], L [20 ]],
456
451
_NoOrder ,
457
452
_NBit [L [1 ], _ItemSize_co ],
458
- np .dtype [np .void ],
453
+ np .dtype [np .void ], # pyright: ignore[reportGeneralTypeIssues]
454
+ Generic [_ItemSize_co ],
459
455
):
460
456
# NOTE: `VoidDType(...)` raises a `TypeError` at the moment
461
457
def __new__ (cls , length : _ItemSize_co , / ) -> NoReturn : ...
@@ -578,8 +574,13 @@ class StringDType( # type: ignore[misc]
578
574
_NativeOrder ,
579
575
_NBit [L [8 ], L [16 ]],
580
576
# TODO: Replace the (invalid) `str` with the scalar type, once implemented
581
- np .dtype [str ], # type: ignore[type-var]
577
+ np .dtype [str ], # type: ignore[type-var] # pyright: ignore[reportGeneralTypeIssues,reportInvalidTypeArguments]
582
578
):
579
+ @property
580
+ def coerce (self ) -> L [True ]: ...
581
+ na_object : ClassVar [MemberDescriptorType ] # does not get instantiated
582
+
583
+ #
583
584
def __new__ (cls , / ) -> StringDType : ...
584
585
def __getitem__ (self , key : Any , / ) -> NoReturn : ...
585
586
@property
0 commit comments