types-array-api 1.1.1__tar.gz → 1.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {types_array_api-1.1.1/src/types_array_api.egg-info → types_array_api-1.1.3}/PKG-INFO +66 -12
  2. {types_array_api-1.1.1 → types_array_api-1.1.3}/README.md +61 -8
  3. {types_array_api-1.1.1 → types_array_api-1.1.3}/pyproject.toml +10 -4
  4. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/_2022_12.py +46 -31
  5. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/_2023_12.py +53 -36
  6. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/_2024_12.py +54 -37
  7. types_array_api-1.1.3/src/array_api/__init__.py +1 -0
  8. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/_draft.py +58 -39
  9. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/cli/_main.py +29 -3
  10. {types_array_api-1.1.1 → types_array_api-1.1.3/src/types_array_api.egg-info}/PKG-INFO +66 -12
  11. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/types_array_api.egg-info/entry_points.txt +1 -0
  12. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/types_array_api.egg-info/requires.txt +5 -3
  13. types_array_api-1.1.3/tests/test_main.py +42 -0
  14. types_array_api-1.1.1/src/array_api/__init__.py +0 -1
  15. types_array_api-1.1.1/tests/test_main.py +0 -25
  16. {types_array_api-1.1.1 → types_array_api-1.1.3}/LICENSE +0 -0
  17. {types_array_api-1.1.1 → types_array_api-1.1.3}/LICENSE-MIT +0 -0
  18. {types_array_api-1.1.1 → types_array_api-1.1.3}/setup.cfg +0 -0
  19. {types_array_api-1.1.1 → types_array_api-1.1.3}/setup.py +0 -0
  20. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/__main__.py +0 -0
  21. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/cli/__init__.py +0 -0
  22. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/cli/cli.py +0 -0
  23. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api/py.typed +0 -0
  24. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/array_api_compat/__init__.pyi +0 -0
  25. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/types_array_api.egg-info/SOURCES.txt +0 -0
  26. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/types_array_api.egg-info/dependency_links.txt +0 -0
  27. {types_array_api-1.1.1 → types_array_api-1.1.3}/src/types_array_api.egg-info/top_level.txt +0 -0
  28. {types_array_api-1.1.1 → types_array_api-1.1.3}/tests/test_cli.py +0 -0
  29. {types_array_api-1.1.1 → types_array_api-1.1.3}/tests/test_dunder_main.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: types-array-api
3
- Version: 1.1.1
3
+ Version: 1.1.3
4
4
  Summary: Typing for array API and array-api-compat
5
5
  Author-email: 34j <34j.95a2p@simplelogin.com>
6
6
  License-Expression: MIT AND Apache-2.0
@@ -22,10 +22,11 @@ Requires-Python: >=3.9
22
22
  Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  License-File: LICENSE-MIT
25
- Requires-Dist: attrs>=25.3.0
26
- Requires-Dist: rich>=10
27
- Requires-Dist: typer<1,>=0.15
28
25
  Requires-Dist: typing-extensions>=4.14.0
26
+ Provides-Extra: cli
27
+ Requires-Dist: attrs>=25.3.0; extra == "cli"
28
+ Requires-Dist: rich>=14; extra == "cli"
29
+ Requires-Dist: typer>=0.16; extra == "cli"
29
30
  Dynamic: license-file
30
31
 
31
32
  # Python array API standard typing
@@ -82,7 +83,7 @@ pip install types-array-api
82
83
 
83
84
  ### Type stubs
84
85
 
85
- Provices type stubs for [`array-api-compat`](https://data-apis.org/array-api-compat/).
86
+ Autocompletion for [`array-api-compat`](https://data-apis.org/array-api-compat/) is available in your IDE **just by installing** this package.
86
87
 
87
88
  ```python
88
89
  import array_api_compat
@@ -93,19 +94,31 @@ xp = array_api_compat.array_namespace(x)
93
94
  ![Screenshot 1](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot1.png)
94
95
  ![Screenshot 2](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot2.png)
95
96
 
96
- ### Array Type
97
+ ### Typing functions using `Array`
97
98
 
98
- ```python
99
- from array_api._2024_12 import Array
99
+ There are multiple ways to type functions:
100
100
 
101
+ - ```python
102
+ from array_api._2024_12 import Array
101
103
 
102
- def my_function[TArray: Array](x: TArray) -> TArray:
103
- return x + 1
104
- ```
104
+ def simple(x: Array) -> Array:
105
+ return x + 1
106
+ ```
107
+
108
+ The simplest way to enjoy autocompletion for `Array`. This should be enough for most use cases.
109
+
110
+ - To make sure that the same type of array is returned (`ndarray`→`ndarray`, `Tensor`→`Tensor`), a `TypeVar` bound to `Array` can be used:
111
+
112
+ ```python
113
+ def generic[TArray: Array](x: TArray) -> TArray:
114
+ return x + 1
115
+ ```
116
+
117
+ ## Advanced Usage
105
118
 
106
119
  ### Namespace Type
107
120
 
108
- You can test if an object matches the Protocol by:
121
+ You can test if an object matches the Protocol as they are [`runtime-checkable`](https://docs.python.org/3/library/typing.html#typing.runtime_checkable):
109
122
 
110
123
  ```python
111
124
  import array_api_strict
@@ -119,6 +132,47 @@ assert isinstance(array_api_strict, ArrayNamespace)
119
132
  assert not isinstance(array_api_strict, ArrayNamespaceFull)
120
133
  ```
121
134
 
135
+ ### Shape Typing
136
+
137
+ - To clarify the input and output shapes, `ShapedArray` and `ShapedAnyArray` can be used:
138
+
139
+ ```python
140
+ from array_api._2024_12 import ShapedAnyArray as Array
141
+
142
+ def sum_last_axis[*TShape](x: Array[*TShape, Any]) -> Array[*TShape]:
143
+ return xp.sum(x, axis=-1)
144
+ ```
145
+
146
+ More complex example using [NewType](https://docs.python.org/3/library/typing.html#newtype) or [type aliases](https://docs.python.org/3/library/typing.html#type-aliases):
147
+
148
+ ```python
149
+ RTheta = NewType("RTheta", int)
150
+ XY = NewType("XY", int)
151
+ def polar_coordinates[*TShape](randtheta: Array[*TShape, RTheta]) -> Array[*TShape, XY]:
152
+ """Convert polar coordinates to Cartesian coordinates."""
153
+ r = randtheta[..., 0]
154
+ theta = randtheta[..., 1]
155
+ x = r * xp.cos(theta)
156
+ y = r * xp.sin(theta)
157
+ return xp.stack((x, y), axis=-1)
158
+ ```
159
+
160
+ Note that `ShapedAnyArray` exists only for **documentation purposes** and internally it is treated as `Array`.
161
+ Using both generic and shaped are impossible due to [python/typing#548](https://github.com/python/typing/issues/548).
162
+
163
+ - Note that the below example is ideal but impossible due to Python specification.
164
+
165
+ ```python
166
+ def impossible[
167
+ TDtype,
168
+ TDevice,
169
+ *TShapeFormer: int,
170
+ *TShapeLatter: int,
171
+ TArray: Array
172
+ ](x: TArray[*TShapeFormer, *TShapeLatter | Literal[1], TDtype, TDevice], y: TArray[*TShapeLatter | Literal[1], TDtype, TDevice]) -> TArray[*TShapeFormer, *TShapeLatter, TDtype, TDevice]:
173
+ return x + y # broadcasting
174
+ ```
175
+
122
176
  ## Contributors ✨
123
177
 
124
178
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -52,7 +52,7 @@ pip install types-array-api
52
52
 
53
53
  ### Type stubs
54
54
 
55
- Provices type stubs for [`array-api-compat`](https://data-apis.org/array-api-compat/).
55
+ Autocompletion for [`array-api-compat`](https://data-apis.org/array-api-compat/) is available in your IDE **just by installing** this package.
56
56
 
57
57
  ```python
58
58
  import array_api_compat
@@ -63,19 +63,31 @@ xp = array_api_compat.array_namespace(x)
63
63
  ![Screenshot 1](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot1.png)
64
64
  ![Screenshot 2](https://raw.githubusercontent.com/34j/array-api/main/docs/_static/screenshot2.png)
65
65
 
66
- ### Array Type
66
+ ### Typing functions using `Array`
67
67
 
68
- ```python
69
- from array_api._2024_12 import Array
68
+ There are multiple ways to type functions:
70
69
 
70
+ - ```python
71
+ from array_api._2024_12 import Array
71
72
 
72
- def my_function[TArray: Array](x: TArray) -> TArray:
73
- return x + 1
74
- ```
73
+ def simple(x: Array) -> Array:
74
+ return x + 1
75
+ ```
76
+
77
+ The simplest way to enjoy autocompletion for `Array`. This should be enough for most use cases.
78
+
79
+ - To make sure that the same type of array is returned (`ndarray`→`ndarray`, `Tensor`→`Tensor`), a `TypeVar` bound to `Array` can be used:
80
+
81
+ ```python
82
+ def generic[TArray: Array](x: TArray) -> TArray:
83
+ return x + 1
84
+ ```
85
+
86
+ ## Advanced Usage
75
87
 
76
88
  ### Namespace Type
77
89
 
78
- You can test if an object matches the Protocol by:
90
+ You can test if an object matches the Protocol as they are [`runtime-checkable`](https://docs.python.org/3/library/typing.html#typing.runtime_checkable):
79
91
 
80
92
  ```python
81
93
  import array_api_strict
@@ -89,6 +101,47 @@ assert isinstance(array_api_strict, ArrayNamespace)
89
101
  assert not isinstance(array_api_strict, ArrayNamespaceFull)
90
102
  ```
91
103
 
104
+ ### Shape Typing
105
+
106
+ - To clarify the input and output shapes, `ShapedArray` and `ShapedAnyArray` can be used:
107
+
108
+ ```python
109
+ from array_api._2024_12 import ShapedAnyArray as Array
110
+
111
+ def sum_last_axis[*TShape](x: Array[*TShape, Any]) -> Array[*TShape]:
112
+ return xp.sum(x, axis=-1)
113
+ ```
114
+
115
+ More complex example using [NewType](https://docs.python.org/3/library/typing.html#newtype) or [type aliases](https://docs.python.org/3/library/typing.html#type-aliases):
116
+
117
+ ```python
118
+ RTheta = NewType("RTheta", int)
119
+ XY = NewType("XY", int)
120
+ def polar_coordinates[*TShape](randtheta: Array[*TShape, RTheta]) -> Array[*TShape, XY]:
121
+ """Convert polar coordinates to Cartesian coordinates."""
122
+ r = randtheta[..., 0]
123
+ theta = randtheta[..., 1]
124
+ x = r * xp.cos(theta)
125
+ y = r * xp.sin(theta)
126
+ return xp.stack((x, y), axis=-1)
127
+ ```
128
+
129
+ Note that `ShapedAnyArray` exists only for **documentation purposes** and internally it is treated as `Array`.
130
+ Using both generic and shaped are impossible due to [python/typing#548](https://github.com/python/typing/issues/548).
131
+
132
+ - Note that the below example is ideal but impossible due to Python specification.
133
+
134
+ ```python
135
+ def impossible[
136
+ TDtype,
137
+ TDevice,
138
+ *TShapeFormer: int,
139
+ *TShapeLatter: int,
140
+ TArray: Array
141
+ ](x: TArray[*TShapeFormer, *TShapeLatter | Literal[1], TDtype, TDevice], y: TArray[*TShapeLatter | Literal[1], TDtype, TDevice]) -> TArray[*TShapeFormer, *TShapeLatter, TDtype, TDevice]:
142
+ return x + y # broadcasting
143
+ ```
144
+
92
145
  ## Contributors ✨
93
146
 
94
147
  Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
@@ -4,7 +4,7 @@ requires = [ "setuptools" ]
4
4
 
5
5
  [project]
6
6
  name = "types-array-api"
7
- version = "1.1.1"
7
+ version = "1.1.3"
8
8
  description = "Typing for array API and array-api-compat"
9
9
  readme = "README.md"
10
10
  license = "MIT AND Apache-2.0"
@@ -26,24 +26,30 @@ classifiers = [
26
26
  ]
27
27
 
28
28
  dependencies = [
29
- "attrs>=25.3.0",
30
- "rich>=10",
31
- "typer>=0.15,<1",
32
29
  "typing-extensions>=4.14.0",
33
30
  ]
31
+ optional-dependencies.cli = [
32
+ "attrs>=25.3.0",
33
+ "rich>=14",
34
+ "typer>=0.16",
35
+ ]
34
36
  urls."Bug Tracker" = "https://github.com/34j/types-array-api/issues"
35
37
  urls.Changelog = "https://github.com/34j/types-array-api/blob/main/CHANGELOG.md"
36
38
  urls.documentation = "https://array-api.readthedocs.io"
37
39
  urls.repository = "https://github.com/34j/types-array-api"
38
40
  scripts.array-api = "array_api.cli:app"
41
+ scripts.types-array-api = "array_api.cli:app"
39
42
 
40
43
  [dependency-groups]
41
44
  dev = [
42
45
  "array-api-compat>=1.11.2",
43
46
  "array-api-strict>=2.3.1",
47
+ "attrs>=25.3.0",
44
48
  "pytest>=8,<9",
45
49
  "pytest-cov>=6,<7",
50
+ "rich>=14.0.0",
46
51
  "ruff>=0.11.13",
52
+ "typer>=0.16.0",
47
53
  ]
48
54
  docs = [
49
55
  "furo>=2023.5.20; python_version>='3.11'",
@@ -5,9 +5,15 @@ from collections.abc import Buffer as SupportsBufferProtocol
5
5
  from collections.abc import Sequence
6
6
  from enum import Enum
7
7
  from types import EllipsisType as ellipsis
8
- from typing import Any, Literal, Protocol, runtime_checkable
8
+ from typing import (
9
+ Any,
10
+ Literal,
11
+ Protocol,
12
+ runtime_checkable,
13
+ )
9
14
 
10
15
  from typing_extensions import CapsuleType as PyCapsule
16
+ from typing_extensions import Self
11
17
 
12
18
  inf = float("inf")
13
19
 
@@ -42,7 +48,7 @@ class finfo_object[TDtype](Protocol):
42
48
 
43
49
 
44
50
  @runtime_checkable
45
- class Array[TArray: Array, TDtype, TDevice](Protocol):
51
+ class Array[TDtype, TDevice](Protocol):
46
52
  def __init__(self) -> None:
47
53
  """Initialize the attributes for the array object class."""
48
54
  ...
@@ -74,7 +80,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
74
80
  ...
75
81
 
76
82
  @property
77
- def mT(self) -> TArray:
83
+ def mT(self) -> Self:
78
84
  """
79
85
  Transpose of a matrix (or a stack of matrices).
80
86
 
@@ -142,7 +148,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
142
148
  ...
143
149
 
144
150
  @property
145
- def T(self) -> TArray:
151
+ def T(self) -> Self:
146
152
  """
147
153
  Transpose of the array.
148
154
 
@@ -160,7 +166,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
160
166
  """
161
167
  ...
162
168
 
163
- def __abs__(self, /) -> TArray:
169
+ def __abs__(self, /) -> Self:
164
170
  """
165
171
  Calculates the absolute value for each element of an array instance.
166
172
 
@@ -191,7 +197,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
191
197
  """
192
198
  ...
193
199
 
194
- def __add__(self, other: int | float | complex | TArray, /) -> TArray:
200
+ def __add__(self, other: int | float | complex | Self, /) -> Self:
195
201
  """
196
202
  Calculates the sum for each element of an array instance with the respective element of the array ``other``.
197
203
 
@@ -219,7 +225,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
219
225
  """
220
226
  ...
221
227
 
222
- def __and__(self, other: int | bool | TArray, /) -> TArray:
228
+ def __and__(self, other: int | bool | Self, /) -> Self:
223
229
  """
224
230
  Evaluates ``self_i & other_i`` for each element of an array instance with the respective element of the array ``other``.
225
231
 
@@ -242,7 +248,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
242
248
  """
243
249
  ...
244
250
 
245
- def __array_namespace__(self, /, *, api_version: str | None = None) -> Any:
251
+ def __array_namespace__(self, /, *, api_version: str | None = None) -> ArrayNamespace[Self, TDtype, TDevice]:
246
252
  """
247
253
  Returns an object that has all the array API functions on it.
248
254
 
@@ -427,7 +433,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
427
433
  """
428
434
  ...
429
435
 
430
- def __eq__(self, other: int | float | complex | bool | TArray, /) -> TArray: # type: ignore[override]
436
+ def __eq__(self, other: int | float | complex | bool | Self, /) -> Self: # type: ignore[override]
431
437
  """
432
438
  Computes the truth value of ``self_i == other_i`` for each element of an array instance with the respective element of the array ``other``.
433
439
 
@@ -485,7 +491,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
485
491
  """
486
492
  ...
487
493
 
488
- def __floordiv__(self, other: int | float | TArray, /) -> TArray:
494
+ def __floordiv__(self, other: int | float | Self, /) -> Self:
489
495
  """
490
496
  Evaluates ``self_i // other_i`` for each element of an array instance with the respective element of the array ``other``.
491
497
 
@@ -511,7 +517,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
511
517
  """
512
518
  ...
513
519
 
514
- def __ge__(self, other: int | float | TArray, /) -> TArray:
520
+ def __ge__(self, other: int | float | Self, /) -> Self:
515
521
  """
516
522
  Computes the truth value of ``self_i >= other_i`` for each element of an array instance with the respective element of the array ``other``.
517
523
 
@@ -537,7 +543,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
537
543
  """
538
544
  ...
539
545
 
540
- def __getitem__(self, key: int | slice | ellipsis | None | tuple[int | slice | ellipsis | None, ...] | TArray, /) -> TArray:
546
+ def __getitem__(self, key: int | slice | ellipsis | None | tuple[int | slice | ellipsis | None, ...] | Self, /) -> Self:
541
547
  """
542
548
  Returns ``self[key]``.
543
549
 
@@ -558,7 +564,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
558
564
  """
559
565
  ...
560
566
 
561
- def __gt__(self, other: int | float | TArray, /) -> TArray:
567
+ def __gt__(self, other: int | float | Self, /) -> Self:
562
568
  """
563
569
  Computes the truth value of ``self_i > other_i`` for each element of an array instance with the respective element of the array ``other``.
564
570
 
@@ -645,7 +651,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
645
651
  """
646
652
  ...
647
653
 
648
- def __invert__(self, /) -> TArray:
654
+ def __invert__(self, /) -> Self:
649
655
  """
650
656
  Evaluates ``~self_i`` for each element of an array instance.
651
657
 
@@ -666,7 +672,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
666
672
  """
667
673
  ...
668
674
 
669
- def __le__(self, other: int | float | TArray, /) -> TArray:
675
+ def __le__(self, other: int | float | Self, /) -> Self:
670
676
  """
671
677
  Computes the truth value of ``self_i <= other_i`` for each element of an array instance with the respective element of the array ``other``.
672
678
 
@@ -692,7 +698,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
692
698
  """
693
699
  ...
694
700
 
695
- def __lshift__(self, other: int | TArray, /) -> TArray:
701
+ def __lshift__(self, other: int | Self, /) -> Self:
696
702
  """
697
703
  Evaluates ``self_i << other_i`` for each element of an array instance with the respective element of the array ``other``.
698
704
 
@@ -715,7 +721,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
715
721
  """
716
722
  ...
717
723
 
718
- def __lt__(self, other: int | float | TArray, /) -> TArray:
724
+ def __lt__(self, other: int | float | Self, /) -> Self:
719
725
  """
720
726
  Computes the truth value of ``self_i < other_i`` for each element of an array instance with the respective element of the array ``other``.
721
727
 
@@ -741,7 +747,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
741
747
  """
742
748
  ...
743
749
 
744
- def __matmul__(self, other: TArray, /) -> TArray:
750
+ def __matmul__(self, other: Self, /) -> Self:
745
751
  """
746
752
  Computes the matrix product.
747
753
 
@@ -791,7 +797,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
791
797
  """
792
798
  ...
793
799
 
794
- def __mod__(self, other: int | float | TArray, /) -> TArray:
800
+ def __mod__(self, other: int | float | Self, /) -> Self:
795
801
  """
796
802
  Evaluates ``self_i % other_i`` for each element of an array instance with the respective element of the array ``other``.
797
803
 
@@ -817,7 +823,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
817
823
  """
818
824
  ...
819
825
 
820
- def __mul__(self, other: int | float | complex | TArray, /) -> TArray:
826
+ def __mul__(self, other: int | float | complex | Self, /) -> Self:
821
827
  """
822
828
  Calculates the product for each element of an array instance with the respective element of the array ``other``.
823
829
 
@@ -848,7 +854,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
848
854
  """
849
855
  ...
850
856
 
851
- def __ne__(self, other: int | float | complex | bool | TArray, /) -> TArray: # type: ignore[override]
857
+ def __ne__(self, other: int | float | complex | bool | Self, /) -> Self: # type: ignore[override]
852
858
  """
853
859
  Computes the truth value of ``self_i != other_i`` for each element of an array instance with the respective element of the array ``other``.
854
860
 
@@ -876,7 +882,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
876
882
  """
877
883
  ...
878
884
 
879
- def __neg__(self, /) -> TArray:
885
+ def __neg__(self, /) -> Self:
880
886
  """
881
887
  Evaluates ``-self_i`` for each element of an array instance.
882
888
 
@@ -908,7 +914,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
908
914
  """
909
915
  ...
910
916
 
911
- def __or__(self, other: int | bool | TArray, /) -> TArray:
917
+ def __or__(self, other: int | bool | Self, /) -> Self:
912
918
  """
913
919
  Evaluates ``self_i | other_i`` for each element of an array instance with the respective element of the array ``other``.
914
920
 
@@ -933,7 +939,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
933
939
  """
934
940
  ...
935
941
 
936
- def __pos__(self, /) -> TArray:
942
+ def __pos__(self, /) -> Self:
937
943
  """
938
944
  Evaluates ``+self_i`` for each element of an array instance.
939
945
 
@@ -954,7 +960,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
954
960
  """
955
961
  ...
956
962
 
957
- def __pow__(self, other: int | float | complex | TArray, /) -> TArray:
963
+ def __pow__(self, other: int | float | complex | Self, /) -> Self:
958
964
  """
959
965
  Calculates an implementation-dependent approximation of exponentiation by raising each element (the base) of an array instance to the power of ``other_i`` (the exponent), where ``other_i`` is the corresponding element of the array ``other``.
960
966
 
@@ -987,7 +993,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
987
993
  """
988
994
  ...
989
995
 
990
- def __rshift__(self, other: int | TArray, /) -> TArray:
996
+ def __rshift__(self, other: int | Self, /) -> Self:
991
997
  """
992
998
  Evaluates ``self_i >> other_i`` for each element of an array instance with the respective element of the array ``other``.
993
999
 
@@ -1010,7 +1016,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
1010
1016
  """
1011
1017
  ...
1012
1018
 
1013
- def __setitem__(self, key: int | slice | ellipsis | tuple[int | slice | ellipsis, ...] | TArray, value: int | float | complex | bool | TArray, /) -> None:
1019
+ def __setitem__(self, key: int | slice | ellipsis | tuple[int | slice | ellipsis, ...] | Self, value: int | float | complex | bool | Self, /) -> None:
1014
1020
  """
1015
1021
  Sets ``self[key]`` to ``value``.
1016
1022
 
@@ -1037,7 +1043,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
1037
1043
  """
1038
1044
  ...
1039
1045
 
1040
- def __sub__(self, other: int | float | complex | TArray, /) -> TArray:
1046
+ def __sub__(self, other: int | float | complex | Self, /) -> Self:
1041
1047
  """
1042
1048
  Calculates the difference for each element of an array instance with the respective element of the array ``other``.
1043
1049
 
@@ -1067,7 +1073,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
1067
1073
  """
1068
1074
  ...
1069
1075
 
1070
- def __truediv__(self, other: int | float | complex | TArray, /) -> TArray:
1076
+ def __truediv__(self, other: int | float | complex | Self, /) -> Self:
1071
1077
  """
1072
1078
  Evaluates ``self_i / other_i`` for each element of an array instance with the respective element of the array ``other``.
1073
1079
 
@@ -1100,7 +1106,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
1100
1106
  """
1101
1107
  ...
1102
1108
 
1103
- def __xor__(self, other: int | bool | TArray, /) -> TArray:
1109
+ def __xor__(self, other: int | bool | Self, /) -> Self:
1104
1110
  """
1105
1111
  Evaluates ``self_i ^ other_i`` for each element of an array instance with the respective element of the array ``other``.
1106
1112
 
@@ -1123,7 +1129,7 @@ class Array[TArray: Array, TDtype, TDevice](Protocol):
1123
1129
  """
1124
1130
  ...
1125
1131
 
1126
- def to_device(self, device: TDevice, /, *, stream: int | Any | None = None) -> TArray:
1132
+ def to_device(self, device: TDevice, /, *, stream: int | Any | None = None) -> Self:
1127
1133
  """
1128
1134
  Copy the array from the device on which it currently resides to the specified ``device``.
1129
1135
 
@@ -7724,3 +7730,12 @@ class FftNamespace[TArray: Array, TDevice](Protocol):
7724
7730
  class ArrayNamespaceFull[TArray: Array, TDtype, TDevice](ArrayNamespace[TArray, TDtype, TDevice], Protocol):
7725
7731
  linalg: LinalgNamespace[TArray, TDtype]
7726
7732
  fft: FftNamespace[TArray, TDevice]
7733
+
7734
+
7735
+ @runtime_checkable
7736
+ class ShapedArray[*T, TDevice, TDtype](Array[TDevice, TDtype], Protocol):
7737
+ @property
7738
+ def shape(self) -> tuple[*T]: ... # type: ignore[override]
7739
+
7740
+
7741
+ type ShapedAnyArray[*T] = ShapedArray[*T, Any, Any]