Skip to content

gh-145577: Correct "Annotating callable objects" explanation#145576

Open
hyperkai wants to merge 5 commits intopython:mainfrom
hyperkai:hyperkai-patch-4
Open

gh-145577: Correct "Annotating callable objects" explanation#145576
hyperkai wants to merge 5 commits intopython:mainfrom
hyperkai:hyperkai-patch-4

Conversation

@hyperkai
Copy link

@hyperkai hyperkai commented Mar 6, 2026

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news labels Mar 6, 2026
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Mar 6, 2026
@hyperkai hyperkai changed the title Correct "Annotating callable objects" explanation gh-145577: Correct "Annotating callable objects" explanation Mar 6, 2026
@hyperkai hyperkai closed this Mar 6, 2026
@hyperkai hyperkai reopened this Mar 6, 2026
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Some formulations are correct while others feel weird to me, but I also want to have other core devs' opinion on this one. Formally, there are a lot of terms that are imprecise in the docs but in practice, having more formal definitions or formulation usually confuses the reader more than helping them. What we try to do now, though, is to avoid using "argument" in place of parameter and vice-versa.

variadic number of arguments, :ref:`overloaded functions <overload>`, or
functions that have keyword-only parameters. However, these signatures can be
expressed by defining a :class:`Protocol` class with a
``Callable`` cannot express complex signatures such as functions that have
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the current formulation.

Functions -- or other :term:`callable` objects -- can be annotated using
:class:`collections.abc.Callable` or deprecated :data:`typing.Callable`.
``Callable[[int], str]`` signifies a function that takes a single parameter
``Callable[[int], str]`` signifies a function that has a single parameter
Copy link
Member

Choose a reason for hiding this comment

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

I prefer "take" but would rather have "takes a single argument". "has" doesn't ring good here.

Copy link
Member

Choose a reason for hiding this comment

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

I find this specific change an improvement, but I'm also fine with "takes a single argument". I don't have a preference between "takes a single argument" and "has a single parameter".

argument list and the return type. The argument list must be a list of types,
a :class:`ParamSpec`, :data:`Concatenate`, or an ellipsis (``...``). The return type must
be a single type.
The type specification ``[]`` must have two objects, a parameter type list and return type.
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 subscription syntax is better. It is confusing to say that [] must have two objects. But parameter list is correct.

functions that have keyword-only parameters. However, these signatures can be
expressed by defining a :class:`Protocol` class with a
``Callable`` cannot express complex signatures such as functions that have
keyword-only or var-positional parameters, or :ref:`overloaded functions <overload>`.
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 we can neither express var-keyword arguments (which is different from keyword-only ones) nor "positional-only". I also think "variadic number of arguments" actually takes into account both positional and keyword-only ones, so I would only add a mention to "positional-only". I would also mention overloaded functions at the end of the sentence though.

@bedevere-app
Copy link

bedevere-app bot commented Mar 7, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

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 skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

The explanation of "Annotating callable objects" section should be made better

3 participants