Skip to content

Commit 16d7708

Browse files
authored
Apply suggestions from code review
Co-authored-by: Athan <kgryte@gmail.com>
1 parent 08bd1f0 commit 16d7708

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

spec/draft/tutorial_api.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
# Array API Tutorial - Migrating API
44

55
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.
77
The patterns discussed in the document cover renaming functions and changing their
8-
signatures, with deprecation periods.
8+
signatures, along with deprecation periods.
99

1010
## Renaming a function
1111

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
1313
the one that is present (or is semantically close enough) in the array API standard.
1414

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
1816
function is as follows:
1917

2018
```py
@@ -34,9 +32,9 @@ def transpose(a, axes=None):
3432
...
3533
```
3634

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,
3836
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
4038
still inform users what has happened and what to do about it:
4139

4240
```py
@@ -56,18 +54,18 @@ Another common pattern during migration to the array API standard is to modify
5654
the signature of a function. The most troublesome parameters are keyword arguments
5755
as it requires users to use the new name.
5856

59-
For this scenario we 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
6058
the standard:
6159

6260
```py
6361
def reshape(a, newshape):
6462
...
6563
```
6664

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
6866
new positional/keyword calling format.
6967

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
7169
only without an extra deprecation message apart from changelog entry, make `shape`
7270
positional or keyword parameter, and make `newshape` and `copy` keyword only:
7371

@@ -77,7 +75,7 @@ def reshape(a, /, shape=None, *, newshape=None, copy=None):
7775
```
7876

7977
This way users calling `reshape(arr, (ax1, ax2, ax3))` will not notice any change
80-
in the behavior of the function. Now we need to iron out other scenarios.
78+
in the behavior of the function. Next, we need to iron out other scenarios.
8179
Users calling the function with a `newshape=...` need to receive a warning with
8280
a proper recommendation, and the extreme case of both `shape` and `newshape` passed
8381
needs to result in an exception:
@@ -98,7 +96,7 @@ def reshape(a, /, shape=None, *, newshape=None, copy=None):
9896
```
9997

10098
Once a deprecation period has passed, we replace the deprecation warning with
101-
a to a `TypeError`, with the same migration message as before:
99+
a `TypeError` and use the same migration message as before:
102100

103101
```py
104102
def reshape(a, /, shape=None, *, newshape=None, copy=None):

0 commit comments

Comments
 (0)