Skip to content

Commit a0bf9f1

Browse files
committed
TYP: add missing "b1" literals for dtype[bool]
1 parent b7b368a commit a0bf9f1

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

numpy/_typing/_char_codes.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import Literal
22

3-
_BoolCodes = Literal["bool", "bool_", "?", "|?", "=?", "<?", ">?"]
3+
_BoolCodes = Literal[
4+
"bool", "bool_",
5+
"?", "|?", "=?", "<?", ">?",
6+
"b1", "|b1", "=b1", "<b1", ">b1",
7+
] # fmt: skip
48

59
_UInt8Codes = Literal["uint8", "u1", "|u1", "=u1", "<u1", ">u1"]
610
_UInt16Codes = Literal["uint16", "u2", "|u2", "=u2", "<u2", ">u2"]

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ from typing import Any, Literal, TypeAlias
77
import numpy as np
88
from numpy.dtypes import StringDType
99

10-
from typing_extensions import assert_type
10+
from typing_extensions import LiteralString, assert_type
1111

1212
# a combination of likely `object` dtype-like candidates (no `_co`)
1313
_PyObjectLike: TypeAlias = Decimal | Fraction | dt.datetime | dt.timedelta
@@ -70,6 +70,8 @@ assert_type(np.dtype(Decimal), np.dtype[np.object_])
7070
assert_type(np.dtype(Fraction), np.dtype[np.object_])
7171

7272
# char-codes
73+
assert_type(np.dtype("?"), np.dtype[np.bool])
74+
assert_type(np.dtype("|b1"), np.dtype[np.bool])
7375
assert_type(np.dtype("u1"), np.dtype[np.uint8])
7476
assert_type(np.dtype("l"), np.dtype[np.long])
7577
assert_type(np.dtype("longlong"), np.dtype[np.longlong])
@@ -111,7 +113,7 @@ assert_type(dtype_U.base, np.dtype[Any])
111113
assert_type(dtype_U.subdtype, None | tuple[np.dtype[Any], tuple[int, ...]])
112114
assert_type(dtype_U.newbyteorder(), np.dtype[np.str_])
113115
assert_type(dtype_U.type, type[np.str_])
114-
assert_type(dtype_U.name, str)
116+
assert_type(dtype_U.name, LiteralString)
115117
assert_type(dtype_U.names, None | tuple[str, ...])
116118

117119
assert_type(dtype_U * 0, np.dtype[np.str_])

0 commit comments

Comments
 (0)