Repository navigation
Reject coerce on non-scalar schemas at compile time - #22
Merged
Merged
Conversation
coerce on an array, object, optional, json, or timestamp schema compiled but silently did nothing (coerceValue's non-scalar arm passes the value through). Non-scalar produced types now fail compilation with a pointer at coercing the element instead, and coerce wrapped around a transform (whose node is not a scalar even when its type is) raises ValueError at schema build. All existing scalar uses are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
.coerceon a non-scalar schema (string.array.coerce,schemaOf(Point).coerce,json().coerce,optional,timestamp) compiled but silently did nothing, becausecoerceValue's non-scalar arm passes the value through untouched. The classic trap wasstring.array.coercelooking like element-wise coercion.Two guard layers, following the
strict()precedent:string, a number, orbool; anything else fails with a message pointing at the correct spelling (coerce the element:int.coerce.array).Schema[string]whose node is actually atransform,primKindis checked and aValueErrorexplains that coerce must come before the transform in the chain.integer().coerce.transform(...)keeps working;transform(...).coerceis rejected.All existing scalar uses (
int.min(0).coerce, sized types likeuint16.coerce,bool.coerce,str().coerce, coerce-then-transform) are unchanged, verified by the suite.Tests
4 new tests (231 total, passing under orc and arc locally): scalar forms still working, non-scalar compile rejections, the transform build-time rejection, and coerce-before-transform continuing to work. README modifiers table updated.