Repository navigation
fix: resolve list-of-models clip defaults at read time - #740
Open
WeAreResilience wants to merge 1 commit into
Open
WeAreResilience wants to merge 1 commit into
WeAreResilience wants to merge 1 commit into
Conversation
An unset clip_under_threshold on a list of models is resolved when the field is read, so explain(), to_json_schema() and to_stickler_config() agree with the score for List[Union[A, B]], Sequence[A], List[Any], a bare List[Optional[A]], a bare List[Annotated[A, ...]] and a forward reference. The deferred-settlement registry, its lock, the fork hook and the per-class finalizers are removed.
This branch has not been deployed
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.
Pull Request
Issue Reference
Closes #691
Description of Changes
An unset
clip_under_thresholdon a list of models is resolved when the field is read.explain(),to_json_schema()andto_stickler_config()report the value the list scores with.Changes Made
os.register_at_forkhook and theweakref.finalizefinalizers.ConfigurationHelper.model_list_clip, and used it fromget_comparison_info,_model_list_export_metadata, the scalar and primitive-list exporters, andStructuredListComparator._list_clip.List[Union[A, B]],Sequence[A],List[Any], a bareList[Optional[A]], a bareList[Annotated[A, ...]]and a forward reference (List["Item"]) reportsFalseand scores with clipping off.Why These Changes Are Needed
Settling the default when the class is defined cannot see a forward reference, and several spellings of a list of models were never rewritten.
explain()then reported the global defaultTruewhile the score kept partial credit. Reading the default at use removes the per-class state and makes those reports match the score.Testing
Unit tests added/updated
Integration tests added/updated
Manual testing completed
All existing tests pass
uv run pytest tests/ -n 4 -q --tb=line— 7497 passed, 14 skipped, 1 xfailed, 391 warnings, in 66.92s.pyproject.tomlalso adds-v --tb=short.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line— 58 passed, 3 warnings. The shapes measured for fix(415): honour clip_under_threshold on List[StructuredModel] fields #627 (the repro both ways, an unsetList[StructuredModel],OptionalandList | None, every spelling including an explicitTrue, JSON Schema and Stickler-config round trips, and the 1.0.x export cases) still score as before. An unset list of models still scores1/3on the repro pair; an explicitTruestill scores0.0.uv run ruff check .— all checks passed.No type checker is configured in
pyproject.toml, the Makefile, or.github/workflows/lint.yaml. CI lint isuv run ruff check.ruff format --checkalready fails on these model files on unmodifieddev, so unrelated lines were left as they were.Mutation proof
The new parity tests fail on unmodified base (
devat 8d7cc65) and pass with the fix. Each mutation was applied to the finished tree, the named test was run, and the tree was restored.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=linethen passed again (58 passed).BASE. New parity tests against unmodified
upstream/dev(8d7cc6525438861369677c388c1e90da28b5c024), with onlysrc/stickler/structured_object_evaluator/models/{configuration_helper,structured_model,structured_list_comparator,json_schema_field_converter}.pychecked out from that commit.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "explain_matches or unrecognised_list_exports or bare_list_of_models_spellings or forward_referenced_list_reports or deferred_clip_registry"— 8 failed, 3 passed, 47 deselected.
test_explain_matches_the_score_for_an_unrecognised_list_of_modelsfailed forUnionList,AnyListandSequenceList(assert True is False).test_bare_list_of_models_spellingsfailed forBareOptionalElementandBareAnnotatedElement.test_an_unrecognised_list_exports_the_clip_it_scores_withfailed forSequenceListandAnyList.test_the_deferred_clip_registry_is_gonefailed because_DEFERRED_CLIP_CLASSESwas present.M1.
model_list_clipreturnedTruewhenis_list_of_structured_modelswas false, andTruefor a bare annotation.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "explain_matches_the_score_for_an_unrecognised_list_of_models or bare_list_of_models_spellings"— caught by
test_explain_matches_the_score_for_an_unrecognised_list_of_models(UnionList,AnyList,SequenceList;assert True is False) and bytest_bare_list_of_models_spellingsforBareOptionalElementandBareAnnotatedElement.M2.
apply_model_list_clipreturned the raw metadata, soto_json_schema()andto_stickler_config()skipped resolution.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "forward_referenced_list_exports or unrecognised_list_exports"— caught by
test_a_forward_referenced_list_exports_and_round_trips_its_default(assert True is Falseon the schema clip) and bytest_an_unrecognised_list_exports_the_clip_it_scores_withforSequenceListandAnyList.M3. Removed the read-time override in
get_comparison_infoand skipped export resolution, leaving the class-definition amendment as the only writer.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "forward_referenced_list_reports_the_default"— caught by
test_a_forward_referenced_list_reports_the_default_it_scores_with(assert True is False).M4. Re-added
_DEFERRED_CLIP_CLASSESand anos.register_at_forkhook.uv run pytest tests/structured_object_evaluator/test_struct_list_clip.py -q --tb=line -k "deferred_clip_registry_is_gone"— caught by
test_the_deferred_clip_registry_is_gone(_DEFERRED_CLIP_CLASSESwas present).Reviewers
@sromoam @digalaviz
Checklist
CHANGELOG.mdentry added under[Unreleased], or not needed becausenothing user-visible changed (see RELEASING.md)
Additional Notes
An unset
List[Any]reportsFalseon every path. A list of non-model values in that field therefore keeps a below-threshold element's partial score, where it previously contributed0.0. Scores for a list of models are unchanged.List[Union[A, B]]is still refused by both exporters, which have no type for a union with a model arm;explain()and the score agree.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.