Skip to content

Commit 673496f

Browse files
committed
💄rearrange protocols in Array
Signed-off-by: nstarman <[email protected]>
1 parent bacf0f9 commit 673496f

File tree

5 files changed

+351
-341
lines changed

5 files changed

+351
-341
lines changed

src/array_api_typing/_array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ def dtype(self, /) -> DTypeT_co:
6868

6969

7070
class Array(
71-
HasArrayNamespace[NamespaceT_co],
7271
# ------ Attributes -------
7372
HasDType[DTypeT_co],
73+
# ------- Methods ---------
74+
HasArrayNamespace[NamespaceT_co],
7475
# -------------------------
7576
Protocol[DTypeT_co, NamespaceT_co],
7677
):

src/array_api_typing/_namespace.py

Whitespace-only changes.

tests/integration/test_numpy1p0.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,9 @@ a_ns: xpt.Array[Any, ModuleType] = nparr
4949
# Note that `np.array_api` uses dtype objects, not dtype classes, so we can't
5050
# type annotate specific dtypes like `np.float32` or `np.int32`.
5151
_: xpt.Array[dtype[Any]] = nparr
52-
_: xpt.Array[dtype[Any]] = nparr_i32
53-
_: xpt.Array[dtype[Any]] = nparr_f32
52+
x_f32: xpt.Array[dtype[Any]] = nparr_f32
53+
x_i32: xpt.Array[dtype[Any]] = nparr_i32
54+
55+
# Check Attribute `.dtype`
56+
_: dtype[Any] = x_f32.dtype
57+
_: dtype[Any] = x_i32.dtype

tests/integration/test_numpy2p0.pyi

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import array_api_typing as xpt
1111
# DType aliases
1212
F32: TypeAlias = np.float32
1313
I32: TypeAlias = np.int32
14+
B: TypeAlias = np.bool_
1415

1516
# Define NDArrays against which we can test the protocols
1617
nparr: npt.NDArray[Any]
1718
nparr_i32: npt.NDArray[I32]
1819
nparr_f32: npt.NDArray[F32]
19-
nparr_b: npt.NDArray[np.bool_]
20+
nparr_b: npt.NDArray[B]
2021

2122
# =========================================================
2223
# `xpt.HasArrayNamespace`
@@ -42,7 +43,7 @@ _: xpt.HasArrayNamespace[dict[str, int]] = nparr # not caught
4243
_: xpt.HasDType[Any] = nparr
4344
_: xpt.HasDType[np.dtype[I32]] = nparr_i32
4445
_: xpt.HasDType[np.dtype[F32]] = nparr_f32
45-
_: xpt.HasDType[np.dtype[np.bool_]] = nparr_b
46+
_: xpt.HasDType[np.dtype[B]] = nparr_b
4647

4748
# =========================================================
4849
# `xpt.Array`
@@ -52,6 +53,11 @@ a_ns: xpt.Array[Any, ModuleType] = nparr
5253

5354
# Check DTypeT_co assignment
5455
_: xpt.Array[Any] = nparr
55-
_: xpt.Array[np.dtype[I32]] = nparr_i32
56-
_: xpt.Array[np.dtype[F32]] = nparr_f32
57-
_: xpt.Array[np.dtype[np.bool_]] = nparr_b
56+
x_f32: xpt.Array[np.dtype[F32]] = nparr_f32
57+
x_i32: xpt.Array[np.dtype[I32]] = nparr_i32
58+
x_b: xpt.Array[np.dtype[B]] = nparr_b
59+
60+
# Check Attribute `.dtype`
61+
_: np.dtype[F32] = x_f32.dtype
62+
_: np.dtype[I32] = x_i32.dtype
63+
_: np.dtype[B] = x_b.dtype

0 commit comments

Comments
 (0)