Skip to content

Commit 6fe2333

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 6fe2333

File tree

2 files changed

+25
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)