Skip to content
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 support for Union types other than None #749

Open
nuclearglick opened this issue Oct 16, 2024 · 0 comments
Open

Add support for Union types other than None #749

nuclearglick opened this issue Oct 16, 2024 · 0 comments

Comments

@nuclearglick
Copy link

Description

msgspec is wonderful, but only supports Unions that have None as the second type.

An example of the problem is:

import msgspec as ms
from typing import Union

class Example(ms.Struct):
    field1: Union[float, int, None] = 1.0

if __name__ == "__main__":
    temp = Example()
    encoded = ms.json.encode(temp)
    decoded = ms.convert(encoded, type=Example)

which will raise the error

TypeError: Type unions containing a custom type may not contain any additional types other than `None` - type `typing.Union[float, int, NoneType]` is not supported
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant