2525 _array_docstrings = tomllib .load (f )["docstrings" ]
2626
2727NS_co = TypeVar ("NS_co" , covariant = True , default = ModuleType )
28- T_contra = TypeVar ("T_contra " , contravariant = True )
28+ Other_contra = TypeVar ("Other_contra " , contravariant = True )
2929R_co = TypeVar ("R_co" , covariant = True , default = Never )
3030
3131
@@ -57,22 +57,42 @@ class Array(
5757 HasArrayNamespace [NS_co ],
5858 op .CanPosSelf ,
5959 op .CanNegSelf ,
60- op .CanAddSame [T_contra , R_co ],
61- op .CanSubSame [T_contra , R_co ],
62- op .CanMulSame [T_contra , R_co ],
63- op .CanTruedivSame [T_contra , R_co ],
64- op .CanFloordivSame [T_contra , R_co ],
65- op .CanModSame [T_contra , R_co ],
66- op .CanPowSame [T_contra , R_co ],
67- Protocol [T_contra , R_co , NS_co ],
60+ op .CanAddSame [Other_contra , R_co ],
61+ op .CanSubSame [Other_contra , R_co ],
62+ op .CanMulSame [Other_contra , R_co ],
63+ op .CanTruedivSame [Other_contra , R_co ],
64+ op .CanFloordivSame [Other_contra , R_co ],
65+ op .CanModSame [Other_contra , R_co ],
66+ op .CanPowSame [Other_contra , R_co ],
67+ Protocol [Other_contra , R_co , NS_co ],
6868):
69- """Array API specification for array object attributes and methods."""
69+ """Array API specification for array object attributes and methods.
70+
71+ The type is: ``Array[-Other = Never, +R = Never, +NS = ModuleType] =
72+ Array[Self | Other, Self | R, NS]`` where:
73+
74+ - `Other` is the type of objects that can be used with the array (e.g., for
75+ binary operations). For example, with numeric arrays, it is common to be
76+ able to add `float` and `int` objects to the array, not just other arrays
77+ of the same dtype. This would be annotated as `Other = float`. When not
78+ specified, `Other` only allows `Self` objects.
79+ - `R` is the return type of the array operations. For example, the return
80+ type of the division between integer arrays can be a float array. This
81+ would be annotated as `R = float`. When not specified, `R` only allows
82+ `Self` objects.
83+ - `NS` is the type of the array namespace. It defaults to `ModuleType`,
84+ which is the most common form of array namespace (e.g., `numpy`, `cupy`,
85+ etc.). However, it can be any type, e.g. a `types.SimpleNamespace`, to
86+ allow for wrapper libraries to semi-dynamically define their own array
87+ namespaces based on the wrapped array type.
88+
89+ """
7090
7191
7292BoolArray : TypeAlias = Array [bool , Array [float , Never , NS_co ], NS_co ]
7393"""Array API specification for boolean array object attributes and methods.
7494
75- Specifically, this type alias fills the `T_contra ` type variable with
95+ Specifically, this type alias fills the `Other_contra ` type variable with
7696`bool`, allowing for `bool` objects to be added, subtracted, multiplied, etc. to
7797the array object.
7898
@@ -81,7 +101,7 @@ class Array(
81101NumericArray : TypeAlias = Array [float | int , NS_co ]
82102"""Array API specification for numeric array object attributes and methods.
83103
84- Specifically, this type alias fills the `T_contra ` type variable with `float
104+ Specifically, this type alias fills the `Other_contra ` type variable with `float
85105| int`, allowing for `float | int` objects to be added, subtracted, multiplied,
86106etc. to the array object.
87107
0 commit comments