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
Add Discriminator Support for Polymorphic Types (Unions) #72
Comments
Another way would be to use literal types for the discriminator, as otherwise the variable could be mutated. mypy just got support for narrowing tagged-unions: https://mypy.readthedocs.io/en/latest/literal_types.html#tagged-unions I know explicit is better than implicit, but it would be cool if typic automatically could handle deserializing in this case: a union of objects each having exactly one field with the same name, which is annotated using a distinct literal type. I think that's pretty unambiguous what the behavior should be. :) |
Now that mypy has defined the expected behavior, I think that's the way to go for sure. |
…-support Add support for Tagged Unions (#72)
Description
A common pattern for polymorphic data in statically typed languages is the use of a
discriminator
field on the object which can be used to determine which type to deserialize said data into. This is main use-case for users registering custom type deserializers intypical
. A better route would be to expose a method at time of declaration by which the user my declare a discriminator.Potential Implementation
This relates to #56
The text was updated successfully, but these errors were encountered: