Skip to content

Commit 637b592

Browse files
committed
✨: add HasArrayPos protocol
1 parent 0906408 commit 637b592

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ 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

src/array_api_typing/_array.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from types import ModuleType
77
from typing import Protocol
8-
from typing_extensions import TypeVar
8+
from typing_extensions import Self, TypeVar
99

1010
NS_co = TypeVar("NS_co", covariant=True, bound=object, default=ModuleType)
1111

@@ -31,8 +31,23 @@ class HasArrayNamespace(Protocol[NS_co]):
3131
def __array_namespace__(self, /, *, api_version: str | None = None) -> NS_co: ... # noqa: PLW3201
3232

3333

34+
class HasArrayPos(Protocol):
35+
"""Protocol for array classes that support the unary plus operator."""
36+
37+
def __pos__(self) -> Self:
38+
"""Evaluates +self_i for each element of an array instance.
39+
40+
Returns:
41+
An array containing the evaluated result for each element. The
42+
returned array must have the same data type as self.
43+
44+
"""
45+
...
46+
47+
3448
class Array(
3549
HasArrayNamespace[NS_co],
50+
HasArrayPos,
3651
Protocol,
3752
):
3853
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)