-
Notifications
You must be signed in to change notification settings - Fork 53
PR: Transform function and method signatures to rst #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
asmeurer
merged 2 commits into
data-apis:main
from
steff456:function_and_method_signatures-rst
Jan 19, 2022
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
61 changes: 29 additions & 32 deletions
61
...ication/function_and_method_signatures.md → ...cation/function_and_method_signatures.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,59 @@ | ||
(function-and-method-signatures)= | ||
.. _function-and-method-signatures: | ||
|
||
# Function and method signatures | ||
Function and method signatures | ||
============================== | ||
|
||
Function signatures in this standard adhere to the following: | ||
|
||
1. Positional parameters must be | ||
[positional-only](https://www.python.org/dev/peps/pep-0570/) parameters. | ||
1. Positional parameters must be `positional-only <https://www.python.org/dev/peps/pep-0570/>`_ parameters. | ||
Positional-only parameters have no externally-usable name. When a function | ||
accepting positional-only parameters is called, positional arguments are | ||
mapped to these parameters based solely on their order. | ||
|
||
_Rationale: existing libraries have incompatible conventions, and using names | ||
of positional parameters is not normal/recommended practice._ | ||
*Rationale: existing libraries have incompatible conventions, and using names | ||
of positional parameters is not normal/recommended practice.* | ||
|
||
```{note} | ||
.. note:: | ||
|
||
Positional-only parameters are only available in Python >= 3.8. Libraries | ||
still supporting 3.7 or 3.6 may consider making the API standard-compliant | ||
namespace >= 3.8. Alternatively, they can add guidance to their users in the | ||
documentation to use the functions as if they were positional-only. | ||
``` | ||
documentation to use the functions as if they were positional-only. | ||
|
||
2. Optional parameters must be | ||
[keyword-only](https://www.python.org/dev/peps/pep-3102/) arguments. | ||
2. Optional parameters must be `keyword-only <https://www.python.org/dev/peps/pep-3102/>`_ arguments. | ||
|
||
_Rationale: this leads to more readable code, and it makes it easier to | ||
*Rationale: this leads to more readable code, and it makes it easier to | ||
evolve an API over time by adding keywords without having to worry about | ||
keyword order._ | ||
keyword order.* | ||
|
||
3. For functions that have a single positional array parameter, that parameter | ||
is called `x`. For functions that have multiple array parameters, those | ||
parameters are called `xi` with `i = 1, 2, ...` (i.e., `x1`, `x2`). | ||
is called ``x``. For functions that have multiple array parameters, those | ||
parameters are called ``xi`` with ``i = 1, 2, ...`` (i.e., ``x1``, ``x2``). | ||
|
||
4. Type annotations are left out of the signatures themselves for readability; however, | ||
they are added to individual parameter descriptions. For code which aims to | ||
adhere to the standard, adding type annotations is strongly recommended. | ||
|
||
A function signature and description will look like: | ||
|
||
``` | ||
funcname(x1, x2, /, *, key1=-1, key2=None) | ||
:: | ||
|
||
Parameters | ||
funcname(x1, x2, /, *, key1=-1, key2=None) -> out: | ||
Parameters | ||
|
||
x1 : array | ||
description | ||
x2 : array | ||
description | ||
key1 : int | ||
description | ||
key2 : Optional[str] | ||
description | ||
x1 : array | ||
description | ||
x2 : array | ||
description | ||
key1 : int | ||
description | ||
key2 : Optional[str] | ||
description | ||
|
||
Returns | ||
Returns | ||
|
||
out : array | ||
description | ||
``` | ||
out : array | ||
description | ||
|
||
Method signatures will follow the same conventions modulo the addition of | ||
`self`. | ||
|
||
Method signatures will follow the same conventions modulo the addition of ``self``. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this code block? Is it supposed to be to show an example of what the documentation in the spec looks like? If so, can we put this dummy function in the code and pull it in with autodoc? Though I honestly don't understand the point of having it at all if that's why it's there. If it's supposed to be to show what a valid function signature looks like, why not make this fully valid Python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is just to explain how function and method signatures are in the spec, this is the current example that is in the spec. What do you think about this @kgryte?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is already there, we can merge this without addressing it. But I do find this a bit confusing.