Skip to content

Sync python-function with the updated tutorial - #840

Open
realpython-bot wants to merge 1 commit into
masterfrom
maintenance/python-function-20260916
Open

realpython-bot wants to merge 1 commit into
masterfrom
maintenance/python-function-20260916

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Companion-code sync for the maintenance update of Defining Your Own Python Function.

What changed

python-function/mutable_argument.py — the mutable-default-argument example had drifted away from the tutorial. The folder defined add_product(item, inventory=[]) and called it with "apple" / "banana", but the article's "Using Mutable Default Values" section defines append_to(item, target=[]) and calls it with 1, 2, 3. add_product() appears nowhere in the tutorial, so a reader downloading the materials couldn't match the file to the text. The script now transcribes the article's block exactly, and its output ([1], [1, 2], [1, 2, 3]) matches the tutorial's output character for character.

What this cycle changed in the article, and why nothing else moved here

The update's code-family fix was the print(average.__doc__) output block, dedented for the Python 3.13+ docstring-whitespace stripping — that's a REPL output block with no twin in this folder (average.py carries the undocumented average(), and there is no docstring script). The rest of the cycle was prose: fourteen {% ref %} glossary links, the PEP 257 link repointed to peps.python.org, and a factual fix to the mutable-default wording. The dependencies pin moved from python==3.13 to python==3.14; this folder has no requirements.txt or constraints.txt (the examples are pure standard library), so there is nothing to re-pin — the repo root already targets py314.

How this was verified

  • Fresh uv venv on the article's new pin, CPython 3.14.6 (python==3.14).
  • Every one of the 17 scripts in python-function/ executed to completion with exit 0 under MPLBACKEND=Agg; mutable_argument.py's output was diffed against the article's pycon block.
  • Repo gates at the version pinned in the root requirements.txt (ruff==0.14.1):
    • uvx ruff@0.14.1 format --check python-function17 files already formatted
    • uvx ruff@0.14.1 check python-functionAll checks passed!

Needs a human merge.

🤖 Generated with Claude Code

… Python Function

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant