Improve Generics docs page#14587
Merged
hauntsaninja merged 4 commits intopython:masterfrom Feb 2, 2023
Merged
Conversation
hauntsaninja
commented
Feb 2, 2023
| s = 'some string' | ||
| Box[int](s) # Type error | ||
|
|
||
| Generic class internals |
Collaborator
Author
There was a problem hiding this comment.
This is moved to the bottom, since it's not the most immediately useful
| my_box = Box(Cat()) | ||
| look_into(my_box) # OK, but mypy would complain here for an invariant type | ||
|
|
||
| .. _type-variable-upper-bound: |
Collaborator
Author
There was a problem hiding this comment.
I move upper bounded type vars before value restricted type vars because they're more useful and easier to understand
Member
JelleZijlstra
left a comment
There was a problem hiding this comment.
Looks good, some nitpicks around imports.
|
|
||
| from typing import TypeVar | ||
| from typing_extensions import Protocol | ||
| from typing import Protocol, TypeVar |
Member
There was a problem hiding this comment.
I would leave this be since we still support 3.7 which doesn't have typing.Protocol.
Collaborator
Author
|
I fixed the ParamSpec / Concatenate imports, but didn't change the Protocol one back as per my comment in #14584 (comment) (Lol, I think mypy will also happily type check this example even on 3.7 because of how magical Protocol is) |
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.
Linking #13681