Conversation
Moving the type info into a separate container is necessary to make Generic structs work.
Also fixes a few bugs
Maybe this will fix the sudden gcov failure?
Some change in `setuptools` or `pip` seems to have dropped the ability to retain the build directory, which we need for generating coverage of the .c files. I've spent a bit of time trying to make this work with `pip install -e .` and can't seem to get things to work. We'll use the deprecated command for now.
Member
Author
|
Alright, things are passing now, merging 🚀. I hope to cut a release containing generics support in the first week of May. If anyone is interested, I'd love it if someone could install from the main branch (https://jcristharif.com/msgspec/install.html#installing-from-github) and try things out. I believe our test suite should cover all the possible edge cases, but if there are bugs it'd be nice to catch 'em now before the release. |
Closed
Member
Author
|
^^^ cc @provinzkraut since you mentioned you were interested in generic support here, and generally provide excellent feedback :). |
This was referenced Apr 25, 2023
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.
This adds full support for encoding/decoding generic
msgspec.Structtypes. Fixes #193.A quick demo:
Recursive and complicated parametrizations also should work, including the weird challenge posted on the pydantic twitter:
In common usage, generics should have no runtime overhead. Since msgspec doesn't validate on
__init__we don't need to generate a new type for each parametrization - type type ofPaginated[Order]istyping._GenericAlias. No magic on our side needed!The scoping rules and behavior for handling complicated parametrized generics are underdocumented in the corresponding PEPs. I believe we've covered all the edge cases here, but would still love for a few users to try this out before it's released. If this passes tests I plan on merging it early, but would hope someone could try this out before it's released.