Repository navigation
Sync python-protocol with the updated tutorial - #911
Merged
Merged
Conversation
… Leveraging Structural Subtyping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Maintenance sync for the tutorial Python Protocols: Leveraging Structural Subtyping.
What changed and why
adder_v5.pyandadder_v6.py: moved the PEP 695 type parameter from the.add()method to theAdderprotocol class (class Adder[T: int | float | str](Protocol)). With the parameter on the method, the method itself is generic, so mypy rejectsIntAdder,FloatAdder, andStrAdderbecause their non-generic.add()methods don't satisfy a generic method. The class-level form is the PEP 695 equivalent ofadder_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) onadder_v5.pyandadder_v6.py: 2 and 3 errors before,Success: no issues foundafter.mypy==2.4.0installed: all exit 0.uvx ruff@0.14.1 format --check python-protocolanduvx ruff@0.14.1 check python-protocol: clean.🤖 Generated with Claude Code