|
| 1 | +# Function and method signatures |
| 2 | + |
| 3 | +Function signatures in this standard adhere to the following: |
| 4 | + |
| 5 | +1. Positional parameters must be |
| 6 | + [positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. |
| 7 | + Positional-only parameters have no externally-usable name. When a function |
| 8 | + accepting positional-only parameters is called, positional arguments are |
| 9 | + mapped to these parameters based solely on their order. |
| 10 | + |
| 11 | + _Rationale: existing libraries have incompatible conventions, and using names |
| 12 | + of positional parameters is not normal/recommended practice._ |
| 13 | + |
| 14 | +2. Optional parameters must be |
| 15 | + [keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments. |
| 16 | + |
| 17 | + _Rationale: this leads to more readable code, and it makes it easier to |
| 18 | + evolve an API over time by adding keywords without having to worry about |
| 19 | + keyword order._ |
| 20 | + |
| 21 | +3. For functions that have a single positional array parameter, that parameter |
| 22 | + is called `x`. For functions that have multiple array parameters, those |
| 23 | + parameters are called `xi` with `i = 1, 2, ...` (i.e., `x1`, `x2`). |
| 24 | + |
| 25 | +4. Type annotations are left out of the signatures themselves for readability; |
| 26 | + they are added to the descriptions of individual parameters however. In code |
| 27 | + which aims to adhere to the standard, adding type annotations is strongly |
| 28 | + recommended. |
| 29 | + |
| 30 | +A function signature and description will look like: |
| 31 | + |
| 32 | +``` |
| 33 | +funcname(x1, x2, /, *, key1=-1, key2=None) |
| 34 | +
|
| 35 | + Parameters |
| 36 | +
|
| 37 | + x1 : array |
| 38 | + description |
| 39 | + x2 : array |
| 40 | + description |
| 41 | + key1 : int |
| 42 | + description |
| 43 | + key2 : Optional[str] |
| 44 | + description |
| 45 | +
|
| 46 | + Returns |
| 47 | +
|
| 48 | + out : array |
| 49 | + description |
| 50 | +``` |
| 51 | + |
| 52 | +Method signatures will follow the same conventions and, modulo the addition of |
| 53 | +`self`. |
0 commit comments