Skip to content

Commit 0cc3a30

Browse files
committed
✨ HasDevice
Signed-off-by: nstarman <[email protected]>
1 parent b8dfad1 commit 0cc3a30

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ ignore = [
126126
"FIX", # flake8-fixme
127127
"ISC001", # Conflicts with formatter
128128
"PYI041", # Use `float` instead of `int | float`
129+
"TD002", # Missing author in TODO
130+
"TD003", # Missing issue link for this TODO
129131
]
130132

131133
[tool.ruff.lint.pydocstyle]

src/array_api_typing/_array.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,19 @@ def dtype(self, /) -> DTypeT_co:
6868
...
6969

7070

71+
class HasDevice(Protocol):
72+
"""Protocol for array classes that have a device attribute."""
73+
74+
@property
75+
def device(self) -> object: # TODO: more specific type
76+
"""Hardware device the array data resides on."""
77+
...
78+
79+
7180
class Array(
7281
# ------ Attributes -------
7382
HasDType[DTypeT_co],
83+
HasDevice,
7484
# ------- Methods ---------
7585
HasArrayNamespace[NamespaceT_co],
7686
# -------------------------

tests/integration/test_numpy1p0.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ x_i32: xpt.Array[dtype[Any]] = nparr_i32
5555
# Check Attribute `.dtype`
5656
_: dtype[Any] = x_f32.dtype
5757
_: dtype[Any] = x_i32.dtype
58+
59+
# Check Attribute `.device`
60+
_: object = x_f32.device
61+
_: object = x_i32.device

tests/integration/test_numpy2p0.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ x_b: xpt.Array[np.dtype[B]] = nparr_b
6161
_: np.dtype[F32] = x_f32.dtype
6262
_: np.dtype[I32] = x_i32.dtype
6363
_: np.dtype[B] = x_b.dtype
64+
65+
# Check Attribute `.device`
66+
_: object = x_f32.device
67+
_: object = x_i32.device
68+
_: object = x_b.device

0 commit comments

Comments
 (0)