Skip to content
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

documentation for function arguments #91485

Open
vainaixr opened this issue Apr 12, 2022 · 4 comments
Open

documentation for function arguments #91485

vainaixr opened this issue Apr 12, 2022 · 4 comments
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@vainaixr
Copy link
Contributor

vainaixr commented Apr 12, 2022

it is confusing what these mean, is there a page which explains the difference between these, or if not, then could there be a page which explains the difference between these, (and more variations)

max(iterable, *[, key, default])
max(arg1, arg2, *args[, key])
iter(object[, sentinal])
input([prompt])
itertools.accumulate(iterable[, func, *, initial=None])
@eugenetriguba
Copy link
Contributor

eugenetriguba commented Apr 13, 2022

@vainaixr
Copy link
Contributor Author

vainaixr commented Apr 13, 2022

i meant the meaning of the arguments, like the *[, i do not know if there are more variations to that.

@JulienPalard
Copy link
Member

JulienPalard commented Apr 13, 2022

Maybe the function docs could be made easier to read by sticking to Python syntax?

As / and * are valid in Python syntax, I can easily imagine a newcomer thinking that *[ is valid too (it may be the case here).

By sticking to valid Python syntax (reminds me of the repr philosophy) developers would read them more easily, maybe, but it means lots of None, like:

max(iterable, *[, key, default])  →  max(iterable, *, key=None, default=None)
max(arg1, arg2, *args[, key])  →  max(arg1, arg2, *args, key=None)
iter(object[, sentinal])  →  iter(object, sentinel=None, /)
input([prompt])  →  input(prompt='', /)
itertools.accumulate(iterable[, func, *, initial=None])  →  itertools.accumulate(iterable, func=None, *, initial=None)

It would mean checking if that's actually true that they expect None as the default value, they may expect a sentinel value. Typically here for input the default value is the empty string, not None.

In case like range where there's no clean way to describe the function using Python, or for functions expecting a sentinel to tell if they received the value or not, we could just list alternative calls, as we actually do for range, like:

class range(stop)
class range(start, stop, step=1)

does my rewritings helps you understand, @vainaijr?

@vainaixr
Copy link
Contributor Author

vainaixr commented Apr 13, 2022

yes, thanks for the explanation

@AlexWaygood AlexWaygood added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Apr 21, 2022
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 15, 2022
…unctions. (pythonGH-96579)

(cherry picked from commit 3c4cbd1)

Co-authored-by: Julien Palard <julien@palard.fr>
miss-islington added a commit that referenced this issue Oct 15, 2022
…ns. (GH-96579)

(cherry picked from commit 3c4cbd1)

Co-authored-by: Julien Palard <julien@palard.fr>
JulienPalard added a commit that referenced this issue Oct 17, 2022
pablogsal pushed a commit that referenced this issue Oct 22, 2022
…ns. (GH-96579)

(cherry picked from commit 3c4cbd1)

Co-authored-by: Julien Palard <julien@palard.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants