-
Notifications
You must be signed in to change notification settings - Fork 118
Expose StructMeta
in Python API
#890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ns like asdict/json to handle structs created by StructMeta subclasses
Thanks! Just to confirm, you pretty much used this comparison right? main...nightsailer:msgspec-x:f9bd49fc907fa4b683f582257a463f3470e1a359 |
Yes, that's right! |
It would be worthwhile to document these changes as well, maybe with some use cases as examples EDIT: @ofek ahah, synchronized comments |
I'll review later tonight but at a quick glance I noticed there is no information about how to use the new capabilities. Do you think you could take a crack at writing some very basic docs and then I can expand or touch up as need be? |
Yeah, good point. No problem, will add something simple! |
How's this, @ofek? |
Re-opening PR for #843 and #844. Copying @nightsailer's initial PR message below:
Expose and Enable Inheritance of StructMeta Metaclass
Changes
StructMeta
metaclass to Python for direct usePy_TPFLAGS_BASETYPE
flag to enable Python inheritance ofStructMeta
Why
This allows users to:
StructMeta
directly without subclassingStruct
StructMeta
behaviorThis PR resolves:
kw_only
forStruct
(e.g.,kw_only_default=True
) #841msgspec.Struct
#837Example
Technical Details
Added StructMeta to module exports in _core.c Added Py_TPFLAGS_BASETYPE flag to StructMetaType Updated init.py to import and expose StructMeta Added type hints in init.pyi
Compatibility
These changes are backward compatible and only add new capabilities without modifying existing behavior.
Related Issues