Repository navigation
docs(521): replace history-narrating comments with the rule they protect - #674
bhattmanthan wants to merge 4 commits into
Conversation
Rewrite "CRITICAL FIX", "PHASE 3 FIX", "Subtask N" and "HYBRID APPROACH" comments across structured_object_evaluator as the invariant they enforce, keeping the issue links. Shorten _ClassGatedComparator's docstring to the gating rule and the warning-replay reason, dropping the before/after score table. Fix the package README: relink ANLSTree, drop the 2025 changelog section, name DerivedMetricsCalculator, replace the hand-copied API section with a docs link, and correct the dict-field limitation. No code changes; full suite passes unmodified.
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
Checked at 87a781bb. The merge base is dev 0a4820f4.
Required (1):
src/stickler/structured_object_evaluator/README.md:425: the example still says# ❌ Not supported - will raise an error. That contradicts the new text at:416-418and the code. #521 names "will raise an error" as the wrong claim, soCloses #521would close the issue with it still in place. Change:425to say what happens, for example# ⚠️ Warns once and scores 0.0. Also reword or drop:440("This limitation ensures reliable, predictable comparison results."). Details are in the inline comment.
Verified: no change in behavior
- AST check: I parsed each of the 10
.pyfiles ondevand on the PR head and comparedast.dump, which ignores comments. With docstrings removed, all 10 are identical. With docstrings kept, 7 are also identical. The other 3 change only docstrings:comparison_helper.py,structured_list_comparator.pyandstructured_model.py. Nothing insrc/reads__doc__. - Full suite on
dev0a4820f4, usingdev's ownsrcand tests: 6768 passed, 3 skipped, 1 xfailed. - Full suite on the PR head
87a781bb, using the PR's ownsrcand tests: 6768 passed, 3 skipped, 1 xfailed. tests/test_docs_build.pyon the PR head: 77 passed.ruff check src/stickler/structured_object_evaluatorpasses on both trees.
Each rewritten comment checked against the code on the head:
_ClassGatedComparator: the wrapper is installed when either list holds a plain model (_holds_a_plain_model)._judgesis_is_plain_model(gt) or _is_plain_model(pred).warn_for_selectedreplays the gate only onmatched_pairs. The docstring states all three correctly.structured_model.pydocstring: "a mapping, a plainBaseModel, and a list of either" matchesis_object_grade_annotation(is_dict_field_type,_is_list_of_mappings,is_plain_model_field_type,_is_list_of_plain_models). Themodel_fields/ PEP 563 comment is now one paragraph and is correct. This hunk is inside_install_object_grade_comparators(:627), not the excluded__init_subclass__(:770).comparison_engine.py:field_comparisonsis collected when it is missing, andConfidenceCalculator.extractstill raisesValueError("No field comparisons found ...")(confidence/calculator.py:53).from_json_schema:validate_json_schemais aDraft7Validatorcheck, so "Validate against the JSON Schema spec" is right.structured_list_comparator.py,configuration_helper.py,comparable_field.py, the calculators,evaluator_format_helper.pyandtrees/base.py: each new comment describes the code next to it.
README checked against dev (PYTHONPATH=<dev>/src):
- A
Dict[str, Any]field withLevenshteinComparator: the class builds with no error. Comparing two identical dicts scores 0.0 and gives one warning ("Field 'attributes' holds a mapping, but its comparator (LevenshteinComparator) scores scal..."). The same field with no comparator getsANLSStarComparator. The new prose at:416-418is right. DerivedMetricsCalculator.add_derived_metrics_to_resultexists (derived_metrics_calculator.py:49).anls_scoredoes takethreshold.docs/docs/API-Reference/api.mdexists, so the link has a page. #135 is the RFC abouttrees/vsComparisonEngine.- The install line already read
pip install stickler-evalondev, so the PR needed no change there.
#521's done-when grep on the head returns only configuration_helper.py:82 and field_converter.py:746. Both are lines the ticket excludes. #516 has removed field_comparator.py:133. The net reduction is 167 lines (the ticket expects about 120). None of the excluded sections are touched.
Optional, not blocking:
README.mdAPI Reference: "both missing from this section previously" describes history, which is what this ticket removes. "See the generated API reference forStructuredModel,anls_score, andcompare_json." would be enough.comparison_helper.py_ClassGatedComparatordocstring: "see #321" now sits next to the pair-population rule. #321 is about whether a refused element should pair at all, which is a different question.comparison_engine.py:337has a trailing space after "here.". Ruff does not flag it.
No CI checks are reported on this head.
| Dictionary fields (`Dict[str, Any]`) with text-based comparators like `LevenshteinComparator` are not supported as they would produce unpredictable results. | ||
| A `Dict[str, Any]` field given a text comparator like `LevenshteinComparator` warns once and | ||
| scores 0.0 rather than comparing meaningfully (see [#297](https://github.com/awslabs/stickler/issues/297)). | ||
| A dict field with no comparator named gets `ANLSStarComparator` instead. |
There was a problem hiding this comment.
Required. This new text is right, but the example 7 lines below still says # ❌ Not supported - will raise an error (:425). #521 names that exact claim as wrong, and the PR says Closes #521.
Measured on dev 0a4820f4 (PYTHONPATH=<dev>/src), with a field attributes: Dict[str, Any] = ComparableField(comparator=LevenshteinComparator(), threshold=0.7):
class def: ok, warnings at def: 0
score identical dicts: 0.0 {'attributes': 0.0}
warnings total: 1 ["Field 'attributes' holds a mapping, but its comparator (LevenshteinComparator) scores scal..."]
Please change :425 to something like # ⚠️ Warns once and scores 0.0 -- not a meaningful comparison. :440 ("This limitation ensures reliable, predictable comparison results.") also no longer fits, because no error is raised. Drop it or reword it.
sromoam
left a comment
There was a problem hiding this comment.
Thanks @bhattmanthan, and thanks for the quick turnaround. I checked ac57e13 against current dev (ce0f710b), and tests/structured_object_evaluator (3723 passed) and tests/test_docs_build.py (77 passed) pass at this head.
vawsgit's required item is resolved: README.md:425 now says what happens, :440 is gone, and the new wording still holds on current dev (one warning, 0.0 against an identical copy). Their three optional notes are still open. I'd take the first two, since "previously" is the kind of text #521 removes and #321 is a different question from the pair rule. Smaller 2 and the inline suggestion on comparison_helper.py:36-38 cover them.
Must fix
- The rewritten
_install_object_grade_comparatorsdocstring states a rule the code doesn't keep (structured_model.py:655-658). "None is substituted at read time alone" is false for a field whose annotation resolves only after the class is defined, andget_comparison_infokeeps a read-time copy of the substitution for exactly that case (configuration_helper.py:757-778). A forward-referenced plain-model field, completed bymodel_rebuild(), scores withANLSStarComparatorand clip off but exportsLevenshteinComparatorwith clip on, and its round trip scores 0.0 where the original scores 0.5. Someone who trusts the docstring could delete that fallback as dead code. Repro and suggestion inline.
Smaller
(#316)should be(#319)(structured_model.py:677). Suggestion inline.- The API Reference link sends
StructuredModelreaders to the wrong page (README.md:392-395). Suggestion inline.
One heads-up: we're not merging anything outside the 1.1.0 milestone until 1.1.0 lands, so this will wait until after that even once it's ready. It also conflicts with dev now, in structured_model.py at the #316 comment, where #670 added a list-of-tuples branch under it. #688 and #690 in 1.1.0 touch that file too, so please bring dev in after 1.1.0 lands rather than now. When you do, keep dev's tuple paragraph and its object_grade / ExactComparator code as they are, and replace only the #316 paragraph.
| All four object-grade shapes (a mapping, a plain `BaseModel`, and a | ||
| list of either) take this one path (#319); none is substituted at | ||
| read time alone, which would let the exported schema disagree with | ||
| the engine for that shape. |
There was a problem hiding this comment.
Must fix 1. This holds for every field whose annotation has resolved when the class is defined, but not for one that resolves later. get_comparison_info substitutes at read time for that case (configuration_helper.py:757-778), and the export then disagrees with the engine. At this head:
class Outer(StructuredModel):
item: "Inner" = ComparableField()
class Inner(BaseModel):
a: str
b: int
Outer.model_rebuild()
class Direct(StructuredModel):
item: Inner = ComparableField() get_comparison_info to_json_schema()
Outer ANLSStarComparator, clip False LevenshteinComparator, clip True
Direct ANLSStarComparator, clip False ANLSStarComparator, clip False
Round-tripping Outer through to_json_schema() and from_json_schema() then scores item {"a": "alpha", "b": 1} against {"a": "alpha", "b": 2} 0.0 with a "holds a mapping" warning, where Outer itself scores the same pair 0.5. dev behaves the same, so the PR doesn't need to change the behaviour, only describe it:
| All four object-grade shapes (a mapping, a plain `BaseModel`, and a | |
| list of either) take this one path (#319); none is substituted at | |
| read time alone, which would let the exported schema disagree with | |
| the engine for that shape. | |
| All four object-grade shapes (a mapping, a plain ``BaseModel``, and a | |
| list of either) take this one path (#319) when the annotation has | |
| resolved by class definition. A field whose annotation resolves only | |
| later, such as a forward reference completed by ``model_rebuild()``, | |
| misses it and is substituted at read time by | |
| ``ConfigurationHelper.get_comparison_info`` instead. |
| # comparator at definition time changes what `to_json_schema()` exports | ||
| # for that shape -- which is exactly the reader alignment this branch is | ||
| # for. All four object-grade shapes now take the one path. | ||
| # All four object-grade shapes take this one path (#316): installing |
There was a problem hiding this comment.
| See the generated [API reference](https://awslabs.github.io/stickler/API-Reference/api/) for | ||
| `StructuredModel`, `anls_score`, and `compare_json` with their full signatures and options — | ||
| including `compare_with`'s options and `anls_score`'s `threshold` parameter, both missing from | ||
| this section previously. |
There was a problem hiding this comment.
StructuredModel and compare_with render on the Models page. API-Reference/api/ has only compare_structured_models, anls_score and compare_json, and its own tip sends readers on to Models. This also drops the "previously" clause:
| See the generated [API reference](https://awslabs.github.io/stickler/API-Reference/api/) for | |
| `StructuredModel`, `anls_score`, and `compare_json` with their full signatures and options — | |
| including `compare_with`'s options and `anls_score`'s `threshold` parameter, both missing from | |
| this section previously. | |
| See the generated API reference for full signatures and options: | |
| [Models](https://awslabs.github.io/stickler/API-Reference/models/) for `StructuredModel` | |
| (including `compare_with`), and [API](https://awslabs.github.io/stickler/API-Reference/api/) | |
| for `anls_score` and `compare_json`. |
| at least one element of EITHER list is a plain model; `_judges` below | ||
| decides which PAIRS it then applies to (a pair with a plain model on at | ||
| least one side, #327's cross-class rule otherwise left alone, see #321). |
There was a problem hiding this comment.
For vawsgit's #321 note, a wording that keeps #321 apart from the pair rule and says which pairs are delegated untouched:
| at least one element of EITHER list is a plain model; `_judges` below | |
| decides which PAIRS it then applies to (a pair with a plain model on at | |
| least one side, #327's cross-class rule otherwise left alone, see #321). | |
| at least one element of EITHER list is a plain model; `_judges` below | |
| then judges only a pair with a plain model on at least one side. A pair | |
| with neither (dict against dict, `StructuredModel` against | |
| `StructuredModel`) is delegated untouched, so #327's open cross-class | |
| rule is not applied to it. See #321 for whether a refused element should | |
| pair at all. |
- structured_model: document that a forward-referenced plain-model field (resolved via model_rebuild()) misses the definition-time install and is substituted at read time by get_comparison_info - structured_model: correct comment reference awslabs#316 -> awslabs#319 - README: point StructuredModel/compare_with to the Models API page and drop the "previously" wording - comparison_helper: clarify which pairs _ClassGatedComparator delegates untouched and keep awslabs#321 separate from the pair rule
|
Thanks @sromoam, applied all four suggestions as written in 856406d: the forward-reference docstring caveat, #316 -> #319, the API Reference links, and the ClassGatedComparator wording. ruff and the structured_object_evaluator and docs-build tests pass locally. I'll bring dev in after 1.1.0 lands and keep dev's tuple paragraph as you described. |
vawsgit
left a comment
There was a problem hiding this comment.
✅ LGTM!
Checked at 856406d8 (full SHA 856406d8a4258035c975db2eb3283067c79ba7ba). Merge base is dev 0a4820f4. dev is now 2cde48fa (1.1.0).
Earlier findings, all cleared
- My required item (
README.md:425, "will raise an error"): the line now reads# ⚠️ Warns once and scores 0.0 -- not a meaningful comparison, and the "reliable, predictable comparison results" sentence is gone. At this head, aDict[str, Any]field withLevenshteinComparatorbuilds with no warning, scores two identical dicts 0.0, and gives one warning in total. - My optional notes: the "previously" wording is gone (
README.md:392-395), and#321is now separate from the pair rule incomparison_helper.py:36-41. - sromoam's must-fix (
structured_model.py:655-658): the docstring now says a forward-referenced field completed bymodel_rebuild()is substituted at read time byConfigurationHelper.get_comparison_info. I ran theOuter/Inner/Directexample from that thread at this head.OutergivesANLSStarComparatorfromget_comparison_infoandLevenshteinComparatorfromto_json_schema().DirectgivesANLSStarComparatorfrom both. So the docstring now matches the code. - sromoam's smaller items:
#316is now#319(structured_model.py:679), and the README links the Models page forStructuredModelandcompare_with. Both pages exist (docs/docs/API-Reference/models.md,api.md).
No change in behavior
- AST comparison of the 10 changed
.pyfiles, merge base against head: with docstrings removed, all 10 are identical. With docstrings kept, 7 are identical and 3 differ only in docstrings (comparison_helper.py,structured_list_comparator.py,structured_model.py). No code undersrc/reads__doc__. - Full suite at the PR head with its own
src: 6751 passed, 13 skipped, 1 xfailed. This matches the PR body. The skips are optional extras that were not installed here. tests/test_docs_build.py: 77 passed.ruff check src/stickler/structured_object_evaluator: all checks passed.- #521's done-when grep (
CRITICAL FIX,PHASE 3,Subtask N,HYBRID APPROACH) in.pyfiles returns onlyconfiguration_helper.py:82andfield_converter.py:746. #521 excludes both lines, and the PR leaves them untouched.
Merge conflict with dev (not a reason to hold the approval)
GitHub reports the PR as conflicting. A trial merge onto dev 2cde48fa conflicts in one file, models/structured_model.py, in two hunks inside _install_object_grade_comparators. The other 10 files merge cleanly. Per the maintainer's note, bring dev in after 1.1.0 lands.
- First hunk (PEP 563 /
model_fieldscomment): keep this PR's shorter comment and keepdev's addednote_deferred_clip_fields(...)paragraph and code. - Second hunk (the
#316comment):devreplaced thecontinuebelow it with aList[StructuredModel]clip-only branch (#415) and a tuple/setExactComparatorbranch (#659). Do not paste "All four object-grade shapes take this one path (#319)" above code that now branches into other shapes. Reword it for whatdevdoes, and keepdev's code as is.
Optional, not blocking
|
Merged dev after 1.1.0 (3772fa4). Conflicts were in structured_model.py and The diff against dev is comments, docstrings and README only (AST-identical |
Issue Reference
Closes #521
Description of Changes
Replaces history-narrating comments ("CRITICAL FIX", "PHASE 3 FIX", "Subtask N", "HYBRID APPROACH") with the invariant each one protects, and fixes the stale
structured_object_evaluator/README.md. Comments, docstrings and Markdown only; no behavior change.Changes Made
aggregate_metrics_calculator.py,comparable_field.py,comparison_engine.py,comparison_helper.py,configuration_helper.py,derived_metrics_calculator.py,evaluator_format_helper.py,structured_list_comparator.py,structured_model.py, andtrees/base.pyto state the rule each one enforces, keeping the related issue links_ClassGatedComparator's docstring to the gating rule and the warning-replay reason, dropping the 40-line before/after score table.structured_object_evaluator/README.md: corrected the install name, relinkedANLSTreeto [RFC]: Resolve the parallel evaluation paths — trees/ (ANLSTree) vs ComparisonEngine #135, dropped the 2025 changelog-style section, namedDerivedMetricsCalculatorcorrectly, replaced the hand-copied API section with a link to the mkdocs API reference, and corrected theDict[str, Any]limitation noteWhy These Changes Are Needed
Many comments narrated how the code got here (review history, ticket/subtask numbers) rather than what it does, making the module harder for a newcomer to read. The package README had also drifted from the current code (wrong install name, wrong location for
ANLSTree, a changelog entry masquerading as documentation, and an incorrect limitations claim).Testing
uv run --frozen pytest -q: 6751 passed,13 skipped, 1 xfailed, no test files edited