Skip to content

Commit 97ac255

Browse files
authored
Merge pull request numpy#26944 from jorenham/core-type_aliases-annotations
TYP: Annotate ``numpy._core._type_aliases``.
2 parents b236ce1 + 3704d97 commit 97ac255

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

numpy/_core/_type_aliases.pyi

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,93 @@
1-
from numpy import generic
1+
from collections.abc import Collection
2+
from typing import Any, Final, Literal as L, TypeAlias, TypedDict
23

3-
sctypeDict: dict[int | str, type[generic]]
4+
import numpy as np
5+
6+
__all__ = (
7+
"_abstract_type_names",
8+
"_aliases",
9+
"_extra_aliases",
10+
"allTypes",
11+
"c_names_dict",
12+
"sctypeDict",
13+
"sctypes",
14+
)
15+
16+
sctypeDict: Final[dict[str, type[np.generic]]]
17+
allTypes: Final[dict[str, type[np.generic]]]
18+
19+
class _CNamesDict(TypedDict):
20+
BOOL: np.dtype[np.bool]
21+
HALF: np.dtype[np.half]
22+
FLOAT: np.dtype[np.single]
23+
DOUBLE: np.dtype[np.double]
24+
LONGDOUBLE: np.dtype[np.longdouble]
25+
CFLOAT: np.dtype[np.csingle]
26+
CDOUBLE: np.dtype[np.cdouble]
27+
CLONGDOUBLE: np.dtype[np.clongdouble]
28+
STRING: np.dtype[np.bytes_]
29+
UNICODE: np.dtype[np.str_]
30+
VOID: np.dtype[np.void]
31+
OBJECT: np.dtype[np.object_]
32+
DATETIME: np.dtype[np.datetime64]
33+
TIMEDELTA: np.dtype[np.timedelta64]
34+
BYTE: np.dtype[np.byte]
35+
UBYTE: np.dtype[np.ubyte]
36+
SHORT: np.dtype[np.short]
37+
USHORT: np.dtype[np.ushort]
38+
INT: np.dtype[np.intc]
39+
UINT: np.dtype[np.uintc]
40+
LONG: np.dtype[np.long]
41+
ULONG: np.dtype[np.ulong]
42+
LONGLONG: np.dtype[np.longlong]
43+
ULONGLONG: np.dtype[np.ulonglong]
44+
45+
c_names_dict: Final[_CNamesDict]
46+
47+
_AbstractTypeName: TypeAlias = L[
48+
"generic",
49+
"flexible",
50+
"character",
51+
"number",
52+
"integer",
53+
"inexact",
54+
"unsignedinteger",
55+
"signedinteger",
56+
"floating",
57+
"complexfloating",
58+
]
59+
_abstract_type_names: Final[set[_AbstractTypeName]]
60+
61+
62+
class _AliasesType(TypedDict):
63+
double: L["float64"]
64+
cdouble: L["complex128"]
65+
single: L["float32"]
66+
csingle: L["complex64"]
67+
half: L["float16"]
68+
bool_: L["bool"]
69+
int_: L["intp"]
70+
uint: L["intp"]
71+
72+
_aliases: Final[_AliasesType]
73+
74+
class _ExtraAliasesType(TypedDict):
75+
float: L["float64"]
76+
complex: L["complex128"]
77+
object: L["object_"]
78+
bytes: L["bytes_"]
79+
a: L["bytes_"]
80+
int: L["int_"]
81+
str: L["str_"]
82+
unicode: L["str_"]
83+
84+
_extra_aliases: Final[_ExtraAliasesType]
85+
86+
class _SCTypes(TypedDict):
87+
int: Collection[type[np.signedinteger[Any]]]
88+
uint: Collection[type[np.unsignedinteger[Any]]]
89+
float: Collection[type[np.floating[Any]]]
90+
complex: Collection[type[np.complexfloating[Any, Any]]]
91+
others: Collection[type[np.flexible | np.bool | np.object_]]
92+
93+
sctypes: Final[_SCTypes]

numpy/typing/tests/data/reveal/numerictypes.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,5 @@ assert_type(np.bool_, type[np.bool])
5353
assert_type(np.typecodes["Character"], Literal["c"])
5454
assert_type(np.typecodes["Complex"], Literal["FDG"])
5555
assert_type(np.typecodes["All"], Literal["?bhilqnpBHILQNPefdgFDGSUVOMm"])
56+
57+
assert_type(np.sctypeDict['uint8'], type[np.generic])

0 commit comments

Comments
 (0)