Skip to content

gh-133438: Fix the use of the terms "argument" and "parameter" in the documentation #135160

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jun 5, 2025

@erlend-aasland erlend-aasland self-requested a review June 5, 2025 09:07
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jun 5, 2025
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jun 5, 2025
…in error messages for invalid function calls
Indicates that the remaining arguments in the Python argument list are
keyword-only. Currently, all keyword-only arguments must also be optional
Indicates that the remaining arguments in the Python argument list can be
supplied only by keyword. Currently, all such arguments must also be optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, “keyword” means something entirely different. IMO we need to use the full term.

Suggested change
supplied only by keyword. Currently, all such arguments must also be optional
supplied only as keyword arguments. Currently, all such arguments must also be optional

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is from the definition of the keyword-only parameter.

      * :dfn:`keyword-only`: specifies an argument that can be supplied only
        by keyword.  Keyword-only parameters can be defined by including a

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of PyArg_ParseTupleAndKeywords, 'keyword' means 'parameter name' rather than 'syntax keyword. So I think Serhiy's revision could be left as is, or changed to

Suggested change
supplied only by keyword. Currently, all such arguments must also be optional
supplied only by parameter name. Currently, all such arguments must also be optional

The keword-only definition is a bit circular. Perhaps by keyword should be changed to by parameter name to break the loop.

positionally. If there are fewer defaults, they correspond to the last n
arguments.
* ``defaults`` is a list of default values for positional-only and
keyword-or-positional parameter.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguments have values. Also, this should be plural.

Suggested change
keyword-or-positional parameter.
keyword-or-positional arguments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only parameters have default values. If the argument is not passed, the the default value is used.

There are two optional keyword-only arguments. The *key* argument specifies
Two optional keyword arguments are supported. The *key* argument specifies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR removes the -only in lots of places. I'd lean toward keeping that by default, even for arguments to make it clearer that you can't pass it positionally.

The * in the signature is only useful if you know what it means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did not mean that they can only be passed by keyword, we would not use word "keyword" here. "Two optional arguments are supported." Misuse "-only" for arguments provokes further errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I agree with Serhiy.

| | | \*\* arg) |
| | co_kwonlyargcount | number of keyword-only |
| | | parameters (not including |
| | | var-positional parameter) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| | | var-positional parameter) |
| | | a ``**kwargs`` parameter) |

IMO **kwargs is clear enough. It's already used in https://docs.python.org/3/library/inspect.html#inspect.Parameter.kind
(And if you disagree: it'd be var-keyword, not var-positional)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this was a typo.

I used terminology from the glossary. In few cases I left *args and **kwargs, but in the module documentation we can allow ourself to be more formal and verbose.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing all this! Most of it looks great.

@@ -410,8 +410,8 @@ inside nested parentheses. They are:

``$``
:c:func:`PyArg_ParseTupleAndKeywords` only:
Indicates that the remaining arguments in the Python argument list are
keyword-only. Currently, all keyword-only arguments must also be optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old wording is clearer here, "keyword-only" is a well-known term in 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.

Keyword-only can be only parameters. Arguments are either positional or keyword. Argument is what we pass to the function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same way, an argument can't be optional: if you omit it, it does not exist at all.

But the terms “optional” and “keyword-only” describe the possibilities you have, not a specific argument in a specific call.

@@ -232,7 +232,7 @@ Scheduling callbacks
Callbacks are called in the order in which they are registered.
Each callback will be called exactly once.

The optional keyword-only *context* argument specifies a
The optional keyword argument *context* specifies a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove "only"? I don't see anything wrong with calling these "keyword-only".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answering my own question after reading more of the diff: "only" means nothing for arguments, since an argument is only ever keyword or positional, not both. So arguments are either positional or keyword; "keyword-only" makes sense only for parameters because parameters can be both at once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the -only is redundant, but it does make things clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the parameter was keyword-or-positional, we would say "The optional argument context".

Copy link
Member

@terryjreedy terryjreedy Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Jelle's 2nd comment that -only can be left removed here and below.

@erlend-aasland erlend-aasland removed their request for review June 5, 2025 14:12
serhiy-storchaka and others added 2 commits June 5, 2025 18:02
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>
@serhiy-storchaka
Copy link
Member Author

Thank you for a review. The changes are not always trivial, and it is not always easy to find a clear and correct alternative, but I think that we should be a bit more formal to prevent further spreading of incorrect terminology.

In some cases, I had to open the original issue or look into the code to understand what it was actually about -- an argument or a parameter.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stopped at ast.rst for now.

Indicates that the remaining arguments in the Python argument list are
keyword-only. Currently, all keyword-only arguments must also be optional
Indicates that the remaining arguments in the Python argument list can be
supplied only by keyword. Currently, all such arguments must also be optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the context of PyArg_ParseTupleAndKeywords, 'keyword' means 'parameter name' rather than 'syntax keyword. So I think Serhiy's revision could be left as is, or changed to

Suggested change
supplied only by keyword. Currently, all such arguments must also be optional
supplied only by parameter name. Currently, all such arguments must also be optional

The keword-only definition is a bit circular. Perhaps by keyword should be changed to by parameter name to break the loop.

Comment on lines 1636 to +1637
formatting styles. The :class:`Formatter` class been enhanced to take an
additional, optional keyword parameter named ``style``. This defaults to
additional, optional keyword argument named ``style``. This defaults to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an alternative change, not necessarily better, would have been /take/have/.

@bedevere-app
Copy link

bedevere-app bot commented Jun 5, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopped at code.h.

@rhettinger
Copy link
Contributor

rhettinger commented Jun 6, 2025

I have doubts about this massive sweep through the docs.

The difference between parameter and argument is a technicality that disagrees with common usage. The norm is to refer to "keyword arguments" and to name the parameter "**kwargs". This is common in blog posts, docs, docstrings and it is what people search for.

My opinion is that the utility and accessibility of our docs would be impaired by this global substitution. There are some places where it makes sense and some where is doesn't sound right.

@nedbat The docs wg should take a look at this one.

@serhiy-storchaka
Copy link
Member Author

It is not so massive comparing with the size of the documentation. "Keyword arguments" is a correct term, this PR does nothing with it. "kwargs" is a nice name for var-keyword parameter, it will contain a dict of keyword arguments.

If we fix the documentation now, there will be fewer errors in the future, because new small pieces of documentation are often written based on existing examples.

@rhettinger
Copy link
Contributor

rhettinger commented Jun 7, 2025

ISTM this ventures far from how everyday Python programmers think, speak, and write about the language. The terms "keyword-only arguments" and "positional only arguments" are commonplace (including in PEP 3102).

In Python books, at conferences, and in blog posts, I don't recall ever hearing "keyword-only parameters" or "positional only parameters." To my ear, that sounds foreign and discordant.

This is a somewhat of a "sweeping PR" and hits 85 files, reversing the wording decisions made by many authors and their reviewers. The premise of the PR seems pedantic to me and at odds with the needs of our users. While I personally am careful when teaching Python to use "argument" and "parameter" precisely, most people do not draw a distinction and use "argument" for both. My opinion is that the PR mostly makes the docs less readable, searchable, and user friendly (though it would be worse if the even more precise term "formal parameter" was used everywhere).

Keep in mind, that the PEPs went through. a heavy discussion phase and no one asked for the title to be changed. Also, the same terminology was used in whatsnew and throughout the docs. It is somewhat heavily vetted as reasonably clear speech and has been in the wild since 2006. We do not need to make this sweeping edit to well established text.

Another thought is the that current terminology reflects a reasonable point of view that / and * are simply restrictions on how arguments may be passed. From that POV, they don't modify the parameters themselves. Accordingly, "positional-only" parameter doesn't make any sense.

Also, there is another issue for users. While folks with a CS background tend to think arguments as being the values that get bound to parameters, other engineering disciplines use the term "parameters" to mean the values themselves (i.e. "we adjusted the parameters" or "parametric equations").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants