Conversation
| - When annotating the field types, use the relevant type variables instead of | ||
| "concrete" types anywhere you want to be generic. | ||
|
|
||
| On Python 3.12+ the type parameters may instead be declared with the type |
Member
There was a problem hiding this comment.
IMO this should be above the other section, and not mentioned as an alternative, since it's the default for generics in newer Python versions. We can then label the existing section as the alternative
Contributor
Author
There was a problem hiding this comment.
Done, the 3.12 form now comes first and the TypeVar steps are labeled as the older spelling.
I kept the running example on the TypeVar form, since it has to work on 3.10 and 3.11 too, and said so in one line right after steps. Happy to convert the example as well if you would rather have it the other way.
This branch was successfully deployed
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.
The "Generic Types" section describes only the
TypeVarplusGeneric[T]form, and the instructions present it as the way to define a generic type, even though msgspec also accepts Python 3.12's type parameter syntax.This adds a short paragraph and example for the
class Paginated[ItemT](msgspec.Struct)form after the existing instructions, and extends the references at the end of the section with a link to PEP 695. The existing steps are left as they are: theGeneric[T]base is required for theTypeVarform, and both names there link into the Python docs.Documentation only, no behavior change.