Skip to content

Commit 2287748

Browse files
committed
✨: add HasArrayAdd protocol to support addition operator for array classes
Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
1 parent 76b0245 commit 2287748

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ version_tuple = {version_tuple!r}
137137
"FBT", # flake8-boolean-trap
138138
"FIX", # flake8-fixme
139139
"ISC001", # Conflicts with formatter
140+
"PLW1641", # Object does not implement `__hash__` method
141+
"PYI041", # Use `float` instead of `int | float`
140142
]
141143

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

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,27 @@ def __neg__(self) -> Self:
6060
...
6161

6262

63+
class HasArrayAdd(Protocol):
64+
"""Protocol for array classes that support the addition operator."""
65+
66+
def __add__(self, other: Self | int | float, /) -> Self:
67+
"""Calculates the sum for each element of an array instance with the respective element of the array other.
68+
69+
Args:
70+
other: addend array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
71+
72+
Returns:
73+
an array containing the element-wise sums. The returned array must have a data type determined by Type Promotion Rules.
74+
75+
""" # noqa: E501
76+
...
77+
78+
6379
class Array(
6480
HasArrayNamespace[NS_co],
6581
HasArrayPos,
6682
HasArrayNeg,
83+
HasArrayAdd,
6784
Protocol,
6885
):
6986
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)