Skip to content

Sync python-set with the updated tutorial - #839

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

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

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Companion-code sync for the maintenance update of Sets in Python (post 152).

What changed and why

The update draft re-pins the tutorial to Python 3.14 and corrects several
transcripts. Four of the scripts in python-set/ no longer produce what the
tutorial shows, so they're brought back in line:

  • pop.py — this cycle's output-drift fix added the echoed return values
    ('Laura', 'Alice') to the two bare employees.pop() calls in the article's
    REPL block. Those two calls were bare in the script too, so the script printed
    nothing for them. They now print(), so the script shows four popped elements
    and only the fifth call raises KeyError: 'pop from an empty set', exactly as
    the tutorial does.
  • superset.py — the "Supersets" section shows
    available_ingredients.issuperset(required_ingredients) returning True, but
    the script called .issubset() and printed False, contradicting the article.
    Fixed to .issuperset().
  • difference_update.py — the file ended with a bare todo_list expression,
    so running it printed nothing at all. The article echoes the updated set, so
    this is now print(todo_list).
  • union.pya.union(b, c, d) discarded its result while the article
    echoes {1, 2, 3, 4, 5, 6, 7}. Now printed.

No dependency file is involved: the tutorial's dependencies field is
python==3.14 with no third-party packages, and python-set/ ships no
requirements.txt. The Python 3.14 bump needed no code change — every script
already runs clean on 3.14.

Nothing else in the folder was touched. The three Python 3.14 traceback-wording
fixes in the article (TypeError: cannot use 'list' as a set element ...,
... cannot use 'tuple' as a set element ..., TypeError: set.symmetric_difference() takes exactly one argument (2 given)) have no twin
here — those failing snippets are not part of any script.

How this was verified

  • Fresh venv on the article's new pin, CPython 3.14.6.
  • Every script in python-set/ executed with MPLBACKEND=Agg. All exit 0
    except pop.py and remove.py, which end on the KeyError the tutorial
    deliberately demonstrates. Output was compared against the article's blocks
    (set-iteration ordering aside, which is unordered by nature).
  • Repo gates with the pinned Ruff from the root requirements.txt:
    uvx ruff@0.14.1 format --check python-set → 22 files already formatted;
    uvx ruff@0.14.1 check python-set → All checks passed!

🤖 Generated with Claude Code

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