msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Draft: feat: allow converting subclasses of tagged structs

Open mishamsk opened this issue 1 year ago • 0 comments

Hi,

This is a very rough draft, opening to see if @jcrist will be open for this feature/approach.

It addresses #656 and my own #541 - allowing to decode data representing a tagged struct subclass in place of the super class.

This feature prevents me from switching to msgspec in my ast library, but should be generally very usable for any tree-like structure/messages.

As of time of writing, in order for this PR to be complete, at least the following has to be handled:

  • [ ] Wire the new allow_tagged_struct_subtypes kwarg into json, msg pack decoders
  • [ ] Properly handle type node / struct info caching. As of now, cache doesn't account for allow_tagged_struct_subtypes, so it will not honor the flag after decoder (type node) is cached for the first time
  • [ ] Add more tests

mishamsk avatar Mar 29 '24 12:03 mishamsk