Skip to content

Commit 33d5bd6

Browse files
committed
refactor DType as a Protocol
Signed-off-by: nstarman <[email protected]>
1 parent 411b5bd commit 33d5bd6

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

src/array_api_stubs/_draft/_types.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424

2525
if TYPE_CHECKING:
2626
from .array_object import Array
27+
from .data_types import DType
2728

2829
array = TypeVar("array", bound="Array")
2930
device = TypeVar("device")
30-
dtype = TypeVar("dtype")
31+
dtype = TypeVar("dtype", bound="DType")
3132
SupportsDLPack = TypeVar("SupportsDLPack")
3233
SupportsBufferProtocol = TypeVar("SupportsBufferProtocol")
3334
PyCapsule = TypeVar("PyCapsule")
+22-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
1-
from ._types import dtype
1+
from typing import TYPE_CHECKING, Protocol
22

3+
if TYPE_CHECKING:
4+
from ._types import dtype
35

4-
def __eq__(self: dtype, other: dtype, /) -> bool:
5-
"""
6-
Computes the truth value of ``self == other`` in order to test for data type object equality.
76

8-
Parameters
9-
----------
10-
self: dtype
11-
data type instance. May be any supported data type.
12-
other: dtype
13-
other data type instance. May be any supported data type.
7+
class DType(Protocol):
148

15-
Returns
16-
-------
17-
out: bool
18-
a boolean indicating whether the data type objects are equal.
19-
"""
9+
def __eq__(self: dtype, other: dtype, /) -> bool:
10+
"""
11+
Computes the truth value of ``self == other`` in order to test for data type object equality.
2012
13+
Parameters
14+
----------
15+
self: dtype
16+
data type instance. May be any supported data type.
17+
other: dtype
18+
other data type instance. May be any supported data type.
2119
22-
__all__ = ["__eq__"]
20+
Returns
21+
-------
22+
out: bool
23+
a boolean indicating whether the data type objects are equal.
24+
"""
25+
...
26+
27+
28+
__all__ = ["DType"]

0 commit comments

Comments
 (0)