Skip to content

gh-145644: Update function related explanations on "controlflow.rst"#145645

Open
hyperkai wants to merge 6 commits intopython:mainfrom
hyperkai:hyperkai-patch-7
Open

gh-145644: Update function related explanations on "controlflow.rst"#145645
hyperkai wants to merge 6 commits intopython:mainfrom
hyperkai:hyperkai-patch-7

Conversation

@hyperkai
Copy link

@hyperkai hyperkai commented Mar 8, 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.

This is the tutorial:

  1. Exceptions messages must only be updated if they match the runtime message.
  2. Leave out var-positional and other terminologies out of the tutorial. It will become too much for a beginner. Formal terms are better suited for formal documentation.



.. _tut-defaultargs:
.. _tut-defaultparams:
Copy link
Member

Choose a reason for hiding this comment

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

Changing this will break URLs, and blog post referrring to that.

and their order is not important. This also includes
non-optional arguments (e.g. ``parrot(voltage=1000)`` is valid too).
No argument may receive a value more than once.
No arguments are possible only if no required parameters exist.
Copy link
Member

Choose a reason for hiding this comment

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

This is not an equivalent sentence. We want to say that you cannot specify a parameter twice.

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function() got multiple values for argument 'a'
TypeError: function() got multiple values for parameter 'a'
Copy link
Member

Choose a reason for hiding this comment

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

Has this been changed at the C level? if not, don't change it.

receives a :ref:`tuple <tut-tuples>` containing the positional
arguments beyond the formal parameter list. (``*name`` must occur
before ``**name``.) For example, if we define a function like this::
When a final var-keyword parameter ``**name`` is present, it defaults to an empty
Copy link
Member

Choose a reason for hiding this comment

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

Formal parameter is correct. And I would keep the "receives an empty dictionary" because it's really a new empty dictionary every time.

arguments beyond the formal parameter list. (``*name`` must occur
before ``**name``.) For example, if we define a function like this::
When a final var-keyword parameter ``**name`` is present, it defaults to an empty
dictionary (see :ref:`typesmapping`) to receive all keyword arguments except for
Copy link
Member

Choose a reason for hiding this comment

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

This is inaccurate. It's not meant to receive the keyword arguments. It's really a dictionary already containing the arguments.

Comment on lines +711 to +712
parameter ``*name`` (described in the next subsection) which defaults to an empty
:ref:`tuple <tut-tuples>` to receive all positional arguments except for those received
Copy link
Member

Choose a reason for hiding this comment

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

This is also wrong.

before ``**name``.) For example, if we define a function like this::
When a final var-keyword parameter ``**name`` is present, it defaults to an empty
dictionary (see :ref:`typesmapping`) to receive all keyword arguments except for
those corresponding to other parameters. This may be combined with a 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.

We don't want to introduce the terminology of "var-positional" or "var-keyword" in this tutorial.

------------------

By default, arguments may be passed to a Python function either by position
By default, arguments can be passed to a Python function either by position
Copy link
Member

Choose a reason for hiding this comment

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

"may" is correct.


If ``/`` and ``*`` are not present in the function definition, arguments may
be passed to a function by position or by keyword.
Positional-or-keyword paremeters don't precede ``/``, don't follow ``*`` or ``*args``,
Copy link
Member

Choose a reason for hiding this comment

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

This is more confusing IMO.

>>>

But using ``/`` (positional only arguments), it is possible since it allows ``name`` as a positional argument and ``'name'`` as a key in the keyword arguments::
But using ``/`` (positional-only parameters) and calling ``foo()`` works because
Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking, you call foo, not foo(). foo() is already the result of the call.

@bedevere-app
Copy link

bedevere-app bot commented Mar 8, 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.

"Defining Functions" to "Function Examples" section should be made better

2 participants