11import ctypes as ct
2- import datetime as dt
32from decimal import Decimal
43from fractions import Fraction
5- from typing import Any , Literal , TypeAlias
64from typing_extensions import LiteralString , assert_type
75
86import numpy as np
97from numpy .dtypes import StringDType
108
11- # a combination of likely `object` dtype-like candidates (no `_co`)
12- _PyObjectLike : TypeAlias = Decimal | Fraction | dt .datetime | dt .timedelta
13-
149dtype_U : np .dtype [np .str_ ]
1510dtype_V : np .dtype [np .void ]
1611dtype_i8 : np .dtype [np .int64 ]
1712
18- py_int_co : type [int | bool ]
19- py_float_co : type [float | int | bool ]
20- py_complex_co : type [complex | float | int | bool ]
21- py_object : type [ _PyObjectLike ]
13+ py_int_co : type [int ]
14+ py_float_co : type [float ]
15+ py_complex_co : type [complex ]
16+ py_object : type
2217py_character : type [str | bytes ]
2318py_flexible : type [str | bytes | memoryview ]
2419
2520ct_floating : type [ct .c_float | ct .c_double | ct .c_longdouble ]
2621ct_number : type [ct .c_uint8 | ct .c_float ]
2722ct_generic : type [ct .c_bool | ct .c_char ]
2823
29- cs_integer : Literal ["u1" , "<i2" , "L" ]
30- cs_number : Literal ["=L" , "i" , "c16" ]
31- cs_flex : Literal [">V" , "S" ]
32- cs_generic : Literal ["H" , "U" , "h" , "|M8[Y]" , "?" ]
33-
34- dt_inexact : np .dtype [np .inexact ]
3524dt_string : StringDType
3625
3726assert_type (np .dtype (np .float64 ), np .dtype [np .float64 ])
3827assert_type (np .dtype (np .float64 , metadata = {"test" : "test" }), np .dtype [np .float64 ])
3928assert_type (np .dtype (np .int64 ), np .dtype [np .int64 ])
4029
4130# String aliases
42- assert_type (np .dtype ("float64" ), np .dtype [np .float64 ])
43- assert_type (np .dtype ("float32" ), np .dtype [np .float32 ])
44- assert_type (np .dtype ("int64" ), np .dtype [np .int64 ])
45- assert_type (np .dtype ("int32" ), np .dtype [np .int32 ])
4631assert_type (np .dtype ("bool" ), np .dtype [np .bool ])
32+ assert_type (np .dtype ("int32" ), np .dtype [np .int32 ])
33+ assert_type (np .dtype ("int64" ), np .dtype [np .int64 ])
34+ assert_type (np .dtype ("float32" ), np .dtype [np .float32 ])
35+ assert_type (np .dtype ("float64" ), np .dtype [np .float64 ])
4736assert_type (np .dtype ("bytes" ), np .dtype [np .bytes_ ])
4837assert_type (np .dtype ("str" ), np .dtype [np .str_ ])
4938
5039# Python types
5140assert_type (np .dtype (bool ), np .dtype [np .bool ])
52- assert_type (np .dtype (py_int_co ), np .dtype [np .int_ | np .bool ])
53- assert_type (np .dtype (int ), np .dtype [np .int_ | np .bool ])
54- assert_type (np .dtype (py_float_co ), np .dtype [np .float64 | np .int_ | np .bool ])
55- assert_type (np .dtype (float ), np .dtype [np .float64 | np .int_ | np .bool ])
56- assert_type (np .dtype (py_complex_co ), np .dtype [np .complex128 | np .float64 | np .int_ | np .bool ])
57- assert_type (np .dtype (complex ), np .dtype [np .complex128 | np .float64 | np .int_ | np .bool ])
58- assert_type (np .dtype (py_object ), np .dtype [np .object_ | Any ])
41+ assert_type (np .dtype (int ), np .dtype [np .int_ ])
42+ assert_type (np .dtype (float ), np .dtype [np .float64 ])
43+ assert_type (np .dtype (complex ), np .dtype [np .complex128 ])
44+ assert_type (np .dtype (object ), np .dtype [np .object_ ])
5945assert_type (np .dtype (str ), np .dtype [np .str_ ])
6046assert_type (np .dtype (bytes ), np .dtype [np .bytes_ ])
61- assert_type (np .dtype (py_character ), np .dtype [np .character ])
6247assert_type (np .dtype (memoryview ), np .dtype [np .void ])
63- assert_type (np .dtype (py_flexible ), np .dtype [np .flexible ])
48+
49+ assert_type (np .dtype (np .signedinteger ), np .dtype [np .signedinteger ])
50+ assert_type (np .dtype (np .unsignedinteger ), np .dtype [np .unsignedinteger ])
51+ assert_type (np .dtype (np .integer ), np .dtype [np .integer ])
52+ assert_type (np .dtype (np .floating ), np .dtype [np .floating ])
53+ assert_type (np .dtype (np .complexfloating ), np .dtype [np .complexfloating ])
54+ assert_type (np .dtype (np .inexact ), np .dtype [np .inexact ])
55+ assert_type (np .dtype (np .number ), np .dtype [np .number ])
56+ # NOTE: `character` and `flexible` always fail on mypy because of some mypy bug
57+ assert_type (np .dtype (np .generic ), np .dtype [np .generic ])
6458
6559assert_type (np .dtype (Decimal ), np .dtype [np .object_ ])
6660assert_type (np .dtype (Fraction ), np .dtype [np .object_ ])
@@ -70,25 +64,22 @@ assert_type(np.dtype("u1"), np.dtype[np.uint8])
7064assert_type (np .dtype ("int_" ), np .dtype [np .intp ])
7165assert_type (np .dtype ("longlong" ), np .dtype [np .longlong ])
7266assert_type (np .dtype (">g" ), np .dtype [np .longdouble ])
73- assert_type (np .dtype (cs_integer ), np .dtype [np .integer ])
74- assert_type (np .dtype (cs_number ), np .dtype [np .number ])
75- assert_type (np .dtype (cs_flex ), np .dtype [np .flexible ])
76- assert_type (np .dtype (cs_generic ), np .dtype [np .generic ])
7767
7868# ctypes
79- assert_type (np .dtype (ct .c_double ), np .dtype [np .float64 ])
80- assert_type (np .dtype (ct .c_longlong ), np .dtype [np .longlong ])
81- assert_type (np .dtype (ct .c_uint32 ), np .dtype [np .uint32 ])
8269assert_type (np .dtype (ct .c_bool ), np .dtype [np .bool ])
83- assert_type (np .dtype (ct .c_char ), np .dtype [np .bytes_ ])
70+ assert_type (np .dtype (ct .c_uint32 ), np .dtype [np .uint32 ])
71+ assert_type (np .dtype (ct .c_ssize_t ), np .dtype [np .intp ])
72+ assert_type (np .dtype (ct .c_longlong ), np .dtype [np .longlong ])
73+ assert_type (np .dtype (ct .c_double ), np .dtype [np .double ])
8474assert_type (np .dtype (ct .py_object ), np .dtype [np .object_ ])
75+ assert_type (np .dtype (ct .c_char ), np .dtype [np .bytes_ ])
8576
8677# Special case for None
8778assert_type (np .dtype (None ), np .dtype [np .float64 ])
8879
8980# Dypes of dtypes
9081assert_type (np .dtype (np .dtype (np .float64 )), np .dtype [np .float64 ])
91- assert_type (np .dtype (dt_inexact ), np .dtype [np .inexact ])
82+ assert_type (np .dtype (np . dtype ( np . inexact ) ), np .dtype [np .inexact ])
9283
9384# Parameterized dtypes
9485assert_type (np .dtype ("S8" ), np .dtype )
0 commit comments