fix: Perform choices validation after parse/mapping time. #179
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #170.
Although i still want to look at this a little bit more. this does add some weird code duplication/different branches. Although I suppose some of that already existed before, it was just built into the parser.In order to avoid needing to physically manipulate the annotations, this PR drops the nicer "choices"
invalid choice: 'thename' (choose from 'one', 'two', 'three', 4)
-style error messages for annotations likeUnion[Literal['one'], Literal['two']]
, because it becomes impractical to support.Instead such annotations get the union-like error message
which is still clear, but not as nice and concise. I think given that unions of only literals (which was the condition for this to work can and probably should be trivially converted to just a literal, this seems like a worthwhile tradeoff.