You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spec/draft/tutorial_api.md
+11-13Lines changed: 11 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,18 +3,16 @@
3
3
# Array API Tutorial - Migrating API
4
4
5
5
The purpose of this tutorial is to show common patterns for migrating your APIs to
6
-
the standard-compatible version in the least disruptive manner for the users.
6
+
the standard-compatible version in the least disruptive manner for users.
7
7
The patterns discussed in the document cover renaming functions and changing their
8
-
signatures, with deprecation periods.
8
+
signatures, along with deprecation periods.
9
9
10
10
## Renaming a function
11
11
12
-
First common migration that might occur is the need to rename a function to
12
+
The first common migration is the need to rename a function to
13
13
the one that is present (or is semantically close enough) in the array API standard.
14
14
15
-
Let's assume our API has a `transpose` function - the one that is not in the standard
16
-
under this name. Instead, `permute_dims` is present for permuting the axes of an
17
-
array, so we can assume this is the one we want to migrate users to. The original
15
+
Let's assume our API has a `transpose` function for permuting the axes of an array, but which has no matching name in the standard. Instead, the standard has a `permute_dims` API which performs the equivalent operation and is the function to which we want users to migrate. The original
18
16
function is as follows:
19
17
20
18
```py
@@ -34,9 +32,9 @@ def transpose(a, axes=None):
34
32
...
35
33
```
36
34
37
-
After a deprecation cycle, when you are ready to remove the deprecated function,
35
+
After a deprecation cycle and when you are ready to remove the deprecated function,
38
36
you should still leave hints for users in case they skipped deprecated versions.
39
-
One option is to track deprecated & removed functions' names in `__getattr__` and
37
+
One option is to track the names of deprecated and removed functions in `__getattr__` and
40
38
still inform users what has happened and what to do about it:
41
39
42
40
```py
@@ -56,18 +54,18 @@ Another common pattern during migration to the array API standard is to modify
56
54
the signature of a function. The most troublesome parameters are keyword arguments
57
55
as it requires users to use the new name.
58
56
59
-
For this scenariowe are about to change `reshape`signature to the one in
57
+
For this scenario, suppose we want to update signature of `reshape`to match the one in
60
58
the standard:
61
59
62
60
```py
63
61
defreshape(a, newshape):
64
62
...
65
63
```
66
64
67
-
We need to rename `newshape` parameter to `shape`, add `copy` parameter, and enforce
65
+
We need to rename `newshape` parameter to `shape`, add a `copy` parameter, and enforce
68
66
new positional/keyword calling format.
69
67
70
-
After researching how users call our `reshape`, we decided to: make `a` positional
68
+
After researching how users call our `reshape`, we decided to do the following: make `a` positional
71
69
only without an extra deprecation message apart from changelog entry, make `shape`
72
70
positional or keyword parameter, and make `newshape` and `copy` keyword only:
0 commit comments