Skip to content

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
merged 2 commits into from
Jan 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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.


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``.