Use 'Invalid value' wording for Literal validation errors#1010
Use 'Invalid value' wording for Literal validation errors#1010Siyet wants to merge 2 commits into859-literal-boolfrom
Conversation
|
The implementation seems fine, so happy to merge. However, I'm not 100% sure this is the right move.
JSON schema refers to collections of possible values as "enums", hence the use of "enum" in the error here. In Python of course these can be represented as a I don't think dropping the "enum" in the error messages makes things more confusing (and still doesn't leak python implementation details), so if you think what you have here is clearer than I'm happy with it. Just sharing context for why things were the way they were before. Up to you. |
|
Thanks for the context. The push toward "Invalid value" came down to one thing: It also gets ambiguous when both coexist: a struct with a |
This would introduce a different ambiguity though: If it refers to an |
|
Fair point, the split is arbitrary. I went through the alternatives: Mention the type in every case. The only candidate term for Literal is "literal", but that's Python-specific ( Qualify as "JSON Schema enum". Doesn't work either: msgspec errors are protocol-agnostic (same message for JSON, MsgPack, Include the field name in the message body. Already covered by the path suffix ( That leaves dropping "enum" from both, using "Invalid value" universally. This is consistent (no type qualifier in either case), doesn't leak implementation details, and matches the existing union tag errors which already use plain "Invalid value". Bigger change than the current PR since it touches Enum errors too, but it's the only option that resolves the inconsistency cleanly. I can update the branch if you and @jcrist are fine with this direction. |
Closes #1009.
Validation errors for
typing.Literaltypes previously used the wordingInvalid enum value <val>, which is misleading because the user is not usingenum.Enum.This change differentiates
EnumandLiteralin_Lookup_OnMissing: whenlookup->cls != NULL(Enum) the message staysInvalid enum value <val>, otherwise (Literal) it becomesInvalid value <val>. The bool literal decode paths added in #1004 are updated to the same wording for consistency.Examples
Before:
After:
Enum messages are unchanged:
Notes
859-literal-bool(Support Literal[True] and Literal[False] types #1004) so the bool literal sites can be updated in the same PR.