Emit missing-required-key errors in schema-declaration order (#484)#545
Open
uttam12331 wants to merge 1 commit into
Open
Emit missing-required-key errors in schema-declaration order (#484)#545uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
alecthomas
approved these changes
Jul 4, 2026
Owner
|
This has conflicts that will need to be resolved. |
Required keys were collected into a `set`, so the `MultipleInvalid` produced for missing required keys came out in an arbitrary, hash-seed-dependent order (the reporter's two-key test failed ~1 in 3 runs). Store the required keys in an insertion-ordered dict (used as an ordered set) and replace the `set.discard()` calls with `dict.pop(key, None)`, so the leftover-required-key errors are emitted in the order the keys were declared in the schema. Behavior is otherwise unchanged. Closes alecthomas#484
uttam12331
force-pushed
the
fix/required-key-error-order-484
branch
from
July 5, 2026 11:45
62c3e2b to
109f955
Compare
Contributor
Author
|
Thanks @alecthomas — rebased on latest |
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
Closes #484.
Required keys were collected into a
set, so theMultipleInvalidraised for missing required keys came out in an arbitrary, hash-seed-dependent order. The reporter's two-key test failed ~1 in 3 runs:Change
Store the required keys in an insertion-ordered
dict(used as an ordered set) instead of aset, and replace theset.discard(...)calls withdict.pop(..., None). The leftover-required-key errors are now emitted in the order the keys were declared in the schema. No other behavior changes.Verified across several
PYTHONHASHSEEDvalues — before, the error order varied per seed; after, it is always declaration order.Tests
Added
test_required_key_error_order_is_stable(5 required keys, asserts the error paths equal the declaration order — an accidental correct ordering on the old code would be ~1 in 120). Full suite passes (170 passed);black --checkandflake8clean. Added a CHANGELOG entry.