Skip to content

Commit a1f43a3

Browse files
committed
✨: add HasArrayRAdd protocol to support right addition operator for array classes
1 parent 1cbc3c8 commit a1f43a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ def __iadd__(self, other: Self | int | float, /) -> Self:
9292
...
9393

9494

95+
class HasArrayRAdd(Protocol):
96+
"""Protocol for array classes that support the right addition operator."""
97+
98+
def __radd__(self, other: Self | int | float, /) -> Self:
99+
"""Calculates the sum for each element of an array instance with the respective element of the array other.
100+
101+
Args:
102+
other: addend array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
103+
104+
Returns:
105+
an array containing the element-wise sums. The returned array must have a data type determined by Type Promotion Rules.
106+
107+
""" # noqa: E501
108+
...
109+
110+
95111
class HasArraySub(Protocol):
96112
"""Protocol for array classes that support the subtraction operator."""
97113

@@ -596,6 +612,7 @@ class Array(
596612
HasArrayNeg,
597613
HasArrayAdd,
598614
HasArrayIAdd,
615+
HasArrayRAdd,
599616
HasArraySub,
600617
HasArrayISub,
601618
HasArrayMul,

0 commit comments

Comments
 (0)