From 44d8c654933e895ea8299a820385fd5a94339759 Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 13 Sep 2021 11:40:13 -0700 Subject: [PATCH 1/2] Add `__index__` to implement `operator.index()` --- spec/API_specification/array_object.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index b1c120311..605c647ff 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -654,6 +654,23 @@ Computes the truth value of `self_i > other_i` for each element of an array inst Element-wise results must equal the results returned by the equivalent element-wise function [`greater(x1, x2)`](elementwise_functions.md#greaterx1-x2-). ``` +(method-__index__)= +### \_\_index\_\_(self, /) + +Converts a zero-dimensional integer array to a Python `int` object. + +#### Parameters + +- **self**: _<array>_ + + - zero-dimensional array instance. Must have an integer data type. + +#### Returns + +- **out**: _<int>_ + + - a Python `int` object representing the single element of the array instance. + (method-__int__)= ### \_\_int\_\_(self, /) From dfd68a464a2cca2238f2d727d2c4da04cd127cbf Mon Sep 17 00:00:00 2001 From: Athan Reines Date: Mon, 13 Sep 2021 11:45:22 -0700 Subject: [PATCH 2/2] Add note --- spec/API_specification/array_object.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/API_specification/array_object.md b/spec/API_specification/array_object.md index 605c647ff..5bc7703c8 100644 --- a/spec/API_specification/array_object.md +++ b/spec/API_specification/array_object.md @@ -659,6 +659,10 @@ Element-wise results must equal the results returned by the equivalent element-w Converts a zero-dimensional integer array to a Python `int` object. +```{note} +This method is called to implement [`operator.index()`](https://docs.python.org/3/reference/datamodel.html#object.__index__). See also [PEP 357](https://www.python.org/dev/peps/pep-0357/). +``` + #### Parameters - **self**: _<array>_