You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EDIT: I don't really see the point in using a literal for a boolean; perhaps there's a reason for when an API always sets a response to True, but then again using bool should be more than enough
I understand that msgspec does not allow to create union types, like in pydantic.
And if success is False, you'd rather get a validation error from msgspec? I'd find that misleading
If i receive error response I will then get "data field not found" error from msgspec, which is even worse then something like "expected success to be True, but is False".
I assumed this would be easy, as we already have string and numeric literals.
Reacted by 叶子, Doug Hoskisson, Thibaut Decombe, Hans Brende, 93578237 and TpattersonDtrac
Activity
jacopoabramo commentedon Jun 24, 2025
why not just use
booldirectly?EDIT: I don't really see the point in using a literal for a boolean; perhaps there's a reason for when an API always sets a response to
True, but then again usingboolshould be more than enoughjack-mcivor commentedon Jun 24, 2025
Using post-init-processing could help here https://jcristharif.com/msgspec/structs.html#post-init-processing
rafalkrupinski commentedon Jun 24, 2025
And if
successis False, you'd rather get a validation error from msgspec? I'd find that misleadingpeku33 commentedon Jun 24, 2025
I'm coming straight from pydantic v2, in which I was able to model api response like this:
I understand that msgspec does not allow to create union types, like in pydantic.
If i receive error response I will then get "data field not found" error from msgspec, which is even worse then something like "expected success to be True, but is False".
I assumed this would be easy, as we already have string and numeric literals.
Siyet commentedon Apr 8, 2026
Resolved in the community fork msgspec-arise: issue #6, released in v0.20.2.
Support Literal[True] and Literal[False] types
Support Literal[True] and Literal[False] types
Support Literal[True] and Literal[False] types (msgspec#1004)