Skip to content

Commit 5e8294d

Browse files
committed
feat: type-check-only dtype protocol
Co-authored-by: NeilGirdhar Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
1 parent 204c20a commit 5e8294d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ version_tuple = {version_tuple!r}
133133
"D107", # Missing docstring in __init__
134134
"D203", # 1 blank line required before class docstring
135135
"D213", # Multi-line docstring summary should start at the second line
136+
"D401", # First line of docstring should be in imperative mood
136137
"FBT", # flake8-boolean-trap
137138
"FIX", # flake8-fixme
138139
"ISC001", # Conflicts with formatter
140+
"PLW1641", # Object does not implement `__hash__` method
139141
]
140142

141143
[tool.ruff.lint.per-file-ignores]

src/array_api_typing/_misc.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
__all__ = ("DType",)
2+
3+
from typing import Protocol, type_check_only
4+
5+
6+
@type_check_only
7+
class DType(Protocol):
8+
"""Protocol for classes that represent a data type.
9+
10+
This `typing.Protocol` is `typing.type_check_only` and cannot be used at
11+
runtime. This limitation is intentional since the array API structurally
12+
defines a ``dtype`` object as anything with an ``__eq__`` method that
13+
compares to another ``dtype`` object. This broad definition means that most
14+
Python objects will satisfy this protocol and can be erroneously considered
15+
a ``dtype``.
16+
17+
"""
18+
19+
def __eq__(self, other: object, /) -> bool:
20+
"""Computes the truth value of ``self == other`` in order to test for data type object equality.""" # noqa: E501
21+
...

0 commit comments

Comments
 (0)