Skip to content

Sync python-protocol with the updated tutorial - #911

Merged
realpython-bot merged 2 commits into
masterfrom
maintenance/python-protocol-20261022
Oct 22, 2026
Merged

realpython-bot merged 2 commits into
masterfrom
maintenance/python-protocol-20261022

Conversation

@realpython-bot

Copy link
Copy Markdown
Collaborator

Maintenance sync for the tutorial Python Protocols: Leveraging Structural Subtyping.

What changed and why

  • adder_v5.py and adder_v6.py: moved the PEP 695 type parameter from the .add() method to the Adder protocol class (class Adder[T: int | float | str](Protocol)). With the parameter on the method, the method itself is generic, so mypy rejects IntAdder, FloatAdder, and StrAdder because their non-generic .add() methods don't satisfy a generic method. The class-level form is the PEP 695 equivalent of adder_v4.py. The tutorial's Python 3.12 syntax block gets the same fix in this update.

Article draft: https://realpython.com/pbjt/blog/post/2561/change/
Maintenance card: https://trello.com/c/hUQ0iXBQ

Verification

  • mypy==2.4.0 (the tutorial's new pin) on adder_v5.py and adder_v6.py: 2 and 3 errors before, Success: no issues found after.
  • Every script in the folder executed on Python 3.12 and 3.14 with mypy==2.4.0 installed: all exit 0.
  • uvx ruff@0.14.1 format --check python-protocol and uvx ruff@0.14.1 check python-protocol: clean.

🤖 Generated with Claude Code

@realpython-bot
realpython-bot merged commit db355ad into master Oct 22, 2026
1 check passed
@realpython-bot
realpython-bot deleted the maintenance/python-protocol-20261022 branch October 22, 2026 09:33
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