Skip to content

Commit f78d155

Browse files
committed
✨: add CanArrayPos protocol
1 parent 382373c commit f78d155

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
@@ -127,6 +127,7 @@ version_tuple = {version_tuple!r}
127127
"D107", # Missing docstring in __init__
128128
"D203", # 1 blank line required before class docstring
129129
"D213", # Multi-line docstring summary should start at the second line
130+
"D401", # First line of docstring should be in imperative mood
130131
"FBT", # flake8-boolean-trap
131132
"FIX", # flake8-fixme
132133
"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 Literal, Protocol
8-
from typing_extensions import TypeVar
8+
from typing_extensions import Self, TypeVar
99

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

@@ -33,8 +33,26 @@ def __array_namespace__(
3333
) -> NS_co: ...
3434

3535

36+
class CanArrayPos(Protocol):
37+
"""Protocol for array classes that support the unary plus operator."""
38+
39+
def __pos__(self) -> Self:
40+
"""Evaluates `+self_i` for each element of an array instance.
41+
42+
Returns:
43+
Self: An array containing the evaluated result for each element.
44+
The returned array must have the same data type as self.
45+
46+
See Also:
47+
array_api_typing.Positive
48+
49+
"""
50+
...
51+
52+
3653
class Array(
3754
HasArrayNamespace[NS_co],
55+
CanArrayPos,
3856
Protocol,
3957
):
4058
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)