-
Notifications
You must be signed in to change notification settings - Fork 76
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
nested tagged unions enumeration #726
Comments
I've thought about my issue and what I'd want a solution to look like. I want to mention #140 because it is a similar problem, but I think over there the issue was different as there was trying to use multiple different top level tagged unions (i'm not sure exactly). Anyway, my desired solution to this is to have this class Inner(msgspec.Struct, tag_field='inner', union_from_subclasses=True): ... the decoder would notice that |
i just noticed #663 which is another way to implement similar capability. I'm not sure if my way work work for that user, but their way would likely work for me. |
@toppk yepp, that's what I was trying to get to. Since @jcrist is clearly busy lately, I'm periodically coming back to consider doing a fork for now. I need this if I'll decide to migrate my commercial project to msgspec... not at that point yet, hence haven't finished what I started as a PoC in #663 |
Question
I've reviewed other issues related to tagged unions. But I just wanted to see if there is some magic I can use.
In using tagged unions, I kinda have parent objects represented the tag. But of course, when setting up the decoder I cannot just give the parent class, but I have to give a union (i get it). But that goes for the nested structs too. This example focuses on that.
if you look at
Title2
vsTitle
below you'll see what I had to do, in order to get decode to work. Obviously encoding doesn't have such an issue.I'd wish for example there would be some magic flag that you could tell the decoder to find the union structs on it's own, instead of having to specify it, and most importantly not being able change outer struct to specify a full union rather then the nested struct parent class (e.g. `Inner')
The text was updated successfully, but these errors were encountered: