Skip to content

Commit b2e998a

Browse files
committed
✨: add CanArrayPos protocol
1 parent 0906408 commit b2e998a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-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: 19 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,26 @@ class HasArrayNamespace(Protocol[NS_co]):
3131
def __array_namespace__(self, /, *, api_version: str | None = None) -> NS_co: ... # noqa: PLW3201
3232

3333

34+
class CanArrayPos(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+
Self: An array containing the evaluated result for each element.
42+
The returned array must have the same data type as self.
43+
44+
See Also:
45+
array_api_typing.Positive
46+
47+
"""
48+
...
49+
50+
3451
class Array(
3552
HasArrayNamespace[NS_co],
53+
CanArrayPos,
3654
Protocol,
3755
):
3856
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)