diff --git a/CHANGELOG.md b/CHANGELOG.md index ab45a0bf..08562111 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,37 @@ Each release links to full notes on the ### Changed +- **Breaking:** a `StructuredModel` field typed `date`, `datetime`, `time`, + `timedelta`, `Decimal`, `UUID` or `Enum` now reaches its comparator, and a + declared comparator is always called. The dispatcher treated only `str`, + `int` and `float` as scalars, so these fell through to the mismatched-types + case: an identical value scored `0.0` and counted as a false discovery, and + the declared comparator (including `DateComparator`) was never called. The + zero-config path (`stickler.evaluate()` on a plain pydantic model) was + unaffected, because its shadow models convert these values first. + + `compare_with()` and `compare()` now share one rule, so the two no longer + disagree on such a pair. Results move for existing callers: + - **A declared comparator is called for any non-structured pair**, including + `bytes`, a custom class, a tuple or set, or a `date` against its ISO string + under `DateComparator`. In `compare_with()` these scored `0.0` without the + comparator being called. + - **An inferred comparator sees only `str`/`int`/`float`, numbers (`Decimal` + included), and related `date`/`time`/`timedelta`/`UUID`/`Enum` values.** + Anything else is a mismatch in both readers. `compare()`, which feeds list + matching, used to call the comparator for such a pair, so a `date` against + its ISO string, `bytes`, or an arbitrary object now score `0.0` there. + - **Enum members match only members of a related `Enum` class.** With an + inferred comparator, two different `IntEnum` or `StrEnum` classes, or a + member against a bare value, are now a mismatch where they used to compare + as `int`/`str`. + - **A `Decimal` is compared with an `int` or `float` as a number.** + + `Tuple` and `Set` fields with an inferred comparator are unchanged + ([#391](https://github.com/awslabs/stickler/issues/391)), and #392 tracks + merging the two readers into one implementation + ([#383](https://github.com/awslabs/stickler/issues/383)) + - **Breaking:** `match_threshold` on a **primitive** field now raises `ValueError`. It is the object-level threshold; nothing read it on a leaf, so `"match_threshold": 0.99` beside a `float` left that field at `threshold` 0.5 diff --git a/docs/docs/Getting-Started/Contributing/architecture.md b/docs/docs/Getting-Started/Contributing/architecture.md index 89635259..29227e9a 100644 --- a/docs/docs/Getting-Started/Contributing/architecture.md +++ b/docs/docs/Getting-Started/Contributing/architecture.md @@ -128,12 +128,18 @@ The dispatcher routes each field comparison through a 5-step decision tree: | 5. **Type-based dispatch** | Route by runtime types to specialized comparator | Terminal | ```python -# See: comparison_dispatcher.py:65-225 +# See: comparison_dispatcher.py, dispatch_field_comparison # Step 5 type routing: # (str|int|float, str|int|float) → FieldComparator +# (value, value), neither a list, dict or model → FieldComparator when +# the field declared its comparator; an inferred one also needs numbers +# incl. Decimal, or related date/time/timedelta/UUID/Enum values (#383). +# The rule is comparison_helper.scalar_pair_reaches_comparator, shared +# with compare_field_raw so compare() and compare_with() agree. # (list, list) where list[0] is StructuredModel → StructuredListComparator # (list, list) otherwise → PrimitiveListComparator # (StructuredModel, StructuredModel) → FieldComparator +# (dict, dict) and (plain BaseModel, plain BaseModel) → FieldComparator # Mismatched types → FD result (score=0.0) ``` diff --git a/docs/docs/Getting-Started/thresholds-and-metrics.md b/docs/docs/Getting-Started/thresholds-and-metrics.md index e36921a2..985ff168 100644 --- a/docs/docs/Getting-Started/thresholds-and-metrics.md +++ b/docs/docs/Getting-Started/thresholds-and-metrics.md @@ -83,7 +83,7 @@ When multiple thresholds could apply, here's which one wins: | Situation | Which threshold applies | |-----------|------------------------| -| **Primitive field comparison** (str, int, float) | Field threshold (`ComparableField(threshold=...)`), else a threshold named on the comparator | +| **Primitive field comparison** (str, int, float, and date, datetime, time, timedelta, Decimal, UUID, Enum) | Field threshold (`ComparableField(threshold=...)`), else a threshold named on the comparator | | **Nested object comparison** | Recurses into fields; each field uses its own field threshold | | **List element pairing** (`List[StructuredModel]`) | Runtime match threshold if provided, else Model match threshold | | **Score clipping** | Field threshold (when `clip_under_threshold=True`) | diff --git a/src/stickler/structured_object_evaluator/models/comparison_dispatcher.py b/src/stickler/structured_object_evaluator/models/comparison_dispatcher.py index 8a50b728..985062cd 100644 --- a/src/stickler/structured_object_evaluator/models/comparison_dispatcher.py +++ b/src/stickler/structured_object_evaluator/models/comparison_dispatcher.py @@ -8,6 +8,7 @@ from pydantic import BaseModel +from .comparison_helper import scalar_pair_reaches_comparator from .configuration_helper import ConfigurationHelper from .null_helper import NullHelper from .result_helper import ResultHelper @@ -190,10 +191,15 @@ def dispatch_field_comparison( # 3. Make the list vs singleton distinction the primary branch # See pseudocode in refactoring discussions for proposed structure. - # CASE 1: Primitive types (str, int, float) - # Delegate to FieldComparator for primitive field comparison - if isinstance(gt_val, (str, int, float)) and isinstance( - pred_val, (str, int, float) + # CASE 1: A pair of non-structured values, for the field's comparator. + # `scalar_pair_reaches_comparator` is the rule, shared with + # compare_field_raw so compare() and compare_with() agree: a declared + # comparator is always called, and an inferred one sees str/int/float, + # numbers incl. Decimal, and related date/time/UUID/Enum values. Before + # #383 only str/int/float got here; everything else fell through to + # CASE 6 and scored 0.0 without the comparator being called. + if scalar_pair_reaches_comparator( + gt_val, pred_val, comparator_explicit=info.comparator_explicit ): return self.field_comparator.compare_primitive_with_scores( gt_val, pred_val, field_name diff --git a/src/stickler/structured_object_evaluator/models/comparison_helper.py b/src/stickler/structured_object_evaluator/models/comparison_helper.py index 14ba37bd..1ffb4e73 100644 --- a/src/stickler/structured_object_evaluator/models/comparison_helper.py +++ b/src/stickler/structured_object_evaluator/models/comparison_helper.py @@ -4,8 +4,14 @@ within StructuredModel instances. """ +import datetime +import decimal +import enum +import uuid from typing import Any, Dict, List +from pydantic import BaseModel + from stickler.comparators.base import BaseComparator from .hungarian_helper import HungarianHelper @@ -172,6 +178,84 @@ def _maybe_absent(val: Any) -> bool: ) +# Scalar types beyond str/int/float that a model field commonly declares. +# `datetime.date` covers `datetime.datetime`, its subclass. +_SCALAR_TYPES = ( + datetime.date, + datetime.time, + datetime.timedelta, + decimal.Decimal, + uuid.UUID, +) +_NUMBERS = (int, float, decimal.Decimal) +# Values with their own branch in both readers; never decided here. +_STRUCTURED = (list, dict, BaseModel) +# Not decided here yet: tuples and sets keep their pre-#383 behaviour in each +# reader until collection comparison has its own contract (#391). +_COLLECTIONS = (tuple, set, frozenset) + + +def scalar_pair_reaches_comparator( + gt_val: Any, pred_val: Any, *, comparator_explicit: bool +) -> bool: + """Whether a field's comparator scores this pair, rather than it mismatching. + + The one rule for a pair of non-structured values, read by both + ``ComparisonDispatcher`` (``compare_with``) and + :meth:`ComparisonHelper.compare_field_raw` (``compare`` and the Hungarian + cost matrix). Spelling it in each let the two disagree, the contradiction + #233 rules out. + + A comparator the field **declared** is always called: the caller chose it + for this field's values, and it decides what it can score, as it already + does for a dict or a plain model. That covers ``bytes``, a custom class, + or a ``date`` against its ISO string under ``DateComparator``. + + A comparator that was **inferred** sees only values it can be trusted + with, since it was never chosen for them. An arbitrary object would reach + ``LevenshteinComparator`` as its repr, and two distinct + ```` reprs are near-identical strings. So the pair + must be: + + - ``str``/``int``/``float``, as before; + - two numbers, ``Decimal`` included; + - ``date``/``time``/``timedelta``/``UUID`` values of related type (``date`` + and ``datetime`` are); + - members of related ``Enum`` classes. Checked first, because an + ``IntEnum``/``StrEnum`` member is also an ``int``/``str``, and two + different such classes, or a member against a bare value, are a + mismatch. + + Before #383 the dispatcher accepted only the first bullet, and a declared + comparator for anything else was never called. + """ + if isinstance(gt_val, _STRUCTURED) or isinstance(pred_val, _STRUCTURED): + return False + if comparator_explicit: + return True + if isinstance(gt_val, enum.Enum) or isinstance(pred_val, enum.Enum): + return ( + isinstance(gt_val, enum.Enum) + and isinstance(pred_val, enum.Enum) + and _related(gt_val, pred_val) + ) + if isinstance(gt_val, (str, int, float)) and isinstance( + pred_val, (str, int, float) + ): + return True + if isinstance(gt_val, _NUMBERS) and isinstance(pred_val, _NUMBERS): + return True + return ( + isinstance(gt_val, _SCALAR_TYPES) + and isinstance(pred_val, _SCALAR_TYPES) + and _related(gt_val, pred_val) + ) + + +def _related(a: Any, b: Any) -> bool: + return isinstance(a, type(b)) or isinstance(b, type(a)) + + class ComparisonHelper: """Helper class for StructuredModel field comparison operations.""" @@ -544,5 +628,21 @@ def compare_field_raw( ): return 0.0 + if isinstance(self_value, BaseModel) and isinstance(other_value, BaseModel): + return comparator.compare(self_value, other_value) + + # Tuples and sets keep their pre-#383 behaviour here (#391). + if isinstance(self_value, _COLLECTIONS) or isinstance( + other_value, _COLLECTIONS + ): + return comparator.compare(self_value, other_value) + + # Every other pair goes through the dispatcher's own rule, so a pair + # `compare_with` calls a mismatch scores 0.0 here too (#233, #383). + if not scalar_pair_reaches_comparator( + self_value, other_value, comparator_explicit=info.comparator_explicit + ): + return 0.0 + # Use the comparator to calculate raw similarity (no threshold) return comparator.compare(self_value, other_value) diff --git a/src/stickler/structured_object_evaluator/models/comparison_info.py b/src/stickler/structured_object_evaluator/models/comparison_info.py index 9bbf25c4..16935582 100644 --- a/src/stickler/structured_object_evaluator/models/comparison_info.py +++ b/src/stickler/structured_object_evaluator/models/comparison_info.py @@ -93,6 +93,7 @@ def __init__( threshold: float = 0.5, weight: float = 1.0, clip_under_threshold: bool = True, + comparator_explicit: bool = False, ): """Initialize comparison configuration. @@ -101,8 +102,12 @@ def __init__( threshold: Minimum similarity score to consider a match (default: 0.5) weight: Weight of this field in the overall score (default: 1.0) clip_under_threshold: Whether to zero out scores below threshold (default: True) + comparator_explicit: Whether the field declared ``comparator``, rather + than it being inferred. A declared comparator is called for any + pair of non-structured values (#383). """ self.comparator = comparator or LevenshteinComparator() + self.comparator_explicit = comparator_explicit self.threshold = threshold self.weight = weight self.clip_under_threshold = clip_under_threshold diff --git a/src/stickler/structured_object_evaluator/models/configuration_helper.py b/src/stickler/structured_object_evaluator/models/configuration_helper.py index 70fb3b16..5833dfb1 100644 --- a/src/stickler/structured_object_evaluator/models/configuration_helper.py +++ b/src/stickler/structured_object_evaluator/models/configuration_helper.py @@ -777,6 +777,10 @@ def get_comparison_info(cls, field_name: str) -> "ComparableFieldConfig": threshold=threshold, weight=weight, clip_under_threshold=clip_under_threshold, + # Read exactly as the substitution above reads it. + comparator_explicit=getattr( + json_func, "_comparator_explicit", True + ), ) # FALLBACK: Legacy JSON schema approach for backward compatibility @@ -818,6 +822,7 @@ def get_comparison_info(cls, field_name: str) -> "ComparableFieldConfig": threshold=threshold, weight=weight, clip_under_threshold=clip_under_threshold, + comparator_explicit="comparator_type" in comparison_config, ) # Check if this is a structured field type that needs special handling diff --git a/tests/structured_object_evaluator/test_scalar_field_dispatch.py b/tests/structured_object_evaluator/test_scalar_field_dispatch.py new file mode 100644 index 00000000..63bf627d --- /dev/null +++ b/tests/structured_object_evaluator/test_scalar_field_dispatch.py @@ -0,0 +1,353 @@ +"""Scalar fields reach their comparator, in both readers (#383). + +``ComparisonDispatcher`` only routed ``str``/``int``/``float`` to the field's +comparator. A field typed ``date``, ``datetime``, ``time``, ``Decimal``, +``UUID`` or a plain ``Enum`` fell through to the mismatched-types case: it +scored 0.0 against an identical value, was counted as a false discovery, and +the comparator was never called, so declaring ``DateComparator`` could not +help. ``stickler.evaluate()`` was unaffected only because its shadow models +turn these values into strings first. + +The rule is shared by ``compare_with()`` and ``compare()``: a comparator the +field declared is always called, and an inferred one sees only the scalar +types it can be trusted with. Tuples and sets are out of scope (#391). +""" + +import datetime +import decimal +import enum +import uuid +from typing import Any, List, Optional, Set, Tuple, Union + +import pytest + +from stickler import ComparableField, StructuredModel +from stickler.comparators import ( + DateComparator, + ExactComparator, + LevenshteinComparator, + NumericComparator, +) +from stickler.comparators.base import BaseComparator + + +class Color(enum.Enum): + RED = "red" + BLUE = "blue" + + +class Size(enum.Enum): + RED = "red" + + +# (type, value, a different value of the same type) +CASES = [ + (datetime.date, datetime.date(2026, 9, 14), datetime.date(2027, 3, 1)), + ( + datetime.datetime, + datetime.datetime(2026, 9, 14, 9), + datetime.datetime(2027, 3, 1, 18), + ), + (datetime.time, datetime.time(9, 30), datetime.time(18, 0)), + (datetime.timedelta, datetime.timedelta(seconds=5), datetime.timedelta(hours=9)), + (decimal.Decimal, decimal.Decimal("12.50"), decimal.Decimal("99.00")), + (uuid.UUID, uuid.UUID(int=1), uuid.UUID(int=2)), + (Color, Color.RED, Color.BLUE), +] +IDS = [c[0].__name__ for c in CASES] + + +def _model(annotation, comparator): + return type( + f"M_{getattr(annotation, '__name__', 'field')}", + (StructuredModel,), + { + "__annotations__": {"f": annotation}, + "f": ComparableField(comparator=comparator), + }, + ) + + +@pytest.mark.parametrize("annotation, value, other", CASES, ids=IDS) +def test_an_identical_value_is_a_true_positive(annotation, value, other): + M = _model(annotation, ExactComparator()) + result = M(f=value).compare_with(M(f=value), include_confusion_matrix=True) + assert result["overall_score"] == pytest.approx(1.0) + counts = result["confusion_matrix"]["overall"] + assert (counts["tp"], counts["fd"]) == (1, 0) + + +@pytest.mark.parametrize("annotation, value, other", CASES, ids=IDS) +def test_a_different_value_is_a_false_discovery(annotation, value, other): + M = _model(annotation, ExactComparator()) + result = M(f=value).compare_with(M(f=other), include_confusion_matrix=True) + assert result["overall_score"] == pytest.approx(0.0) + counts = result["confusion_matrix"]["overall"] + assert (counts["tp"], counts["fd"]) == (0, 1) + + +@pytest.mark.parametrize("annotation, value, other", CASES, ids=IDS) +def test_the_declared_comparator_is_called(annotation, value, other, monkeypatch): + calls = [] + original = ExactComparator.compare + + def spy(self, a, b): + calls.append((a, b)) + return original(self, a, b) + + monkeypatch.setattr(ExactComparator, "compare", spy) + M = _model(annotation, ExactComparator()) + M(f=value).compare_with(M(f=value)) + assert calls == [(value, value)] + + +def test_date_comparator_scores_a_date_field(): + """The case from the issue: a perfect match was reported as an FD.""" + + class Shipped(StructuredModel): + ship_date: datetime.date = ComparableField(comparator=DateComparator()) + + d = datetime.date(2026, 9, 14) + result = Shipped(ship_date=d).compare_with( + Shipped(ship_date=d), include_confusion_matrix=True + ) + counts = result["confusion_matrix"]["overall"] + assert (counts["tp"], counts["fd"]) == (1, 0) + + +def test_numeric_comparator_scores_a_decimal_field(): + class Invoice(StructuredModel): + total: decimal.Decimal = ComparableField(comparator=NumericComparator()) + + result = Invoice(total=decimal.Decimal("12.50")).compare_with( + Invoice(total=decimal.Decimal("12.5")) + ) + assert result["overall_score"] == pytest.approx(1.0) + + +def test_a_date_and_a_datetime_reach_the_comparator(): + """`datetime` subclasses `date`, so the pair is related, not mismatched.""" + + class M(StructuredModel): + when: Union[datetime.datetime, datetime.date] = ComparableField( + comparator=DateComparator() + ) + + result = M(when=datetime.date(2026, 9, 14)).compare_with( + M(when=datetime.datetime(2026, 9, 14, 9)) + ) + assert result["overall_score"] == pytest.approx(1.0) + + +class Blob: + """A non-pydantic type: its default repr differs only by address.""" + + +class Point: + def __init__(self, x, y): + self.x, self.y = x, y + + +class BytesEqual(BaseComparator): + def _compare(self, a, b): + return 1.0 if a == b else 0.0 + + +class PointDistance(BaseComparator): + def _compare(self, a, b): + return max(0.0, 1.0 - (abs(a.x - b.x) + abs(a.y - b.y)) / 10) + + +class Jaccard(BaseComparator): + """Written for sets: it needs the values as sets, not a stringified form.""" + + def _compare(self, a, b): + return len(a & b) / len(a | b) + + +def _readers(model, gt, pred): + """compare_with()'s overall score and compare(), for one-field models. + + ``compare()`` is the raw score and ``compare_with()`` clips a score under + the field threshold, so tests that compare the two either use scores of + 0.0 and 1.0 or turn clipping off. + """ + a, b = model(f=gt), model(f=pred) + return a.compare_with(b)["overall_score"], a.compare(b) + + +class TestAnInferredComparatorSeesOnlyTrustedScalars: + """No comparator declared, so the pair must be of a kind it can score.""" + + @pytest.mark.parametrize( + "gt, pred", + [ + (datetime.date(2026, 9, 14), "2026-09-14"), + (Color.RED, Size.RED), + (uuid.UUID(int=1), decimal.Decimal(1)), + (b"abc", b"abc"), + ], + ids=["date-vs-str", "two-enum-classes", "uuid-vs-decimal", "bytes"], + ) + def test_unrelated_or_untrusted_types_are_a_mismatch(self, gt, pred): + class M(StructuredModel): + f: Any = ComparableField() + + result = M(f=gt).compare_with(M(f=pred), include_confusion_matrix=True) + assert result["overall_score"] == pytest.approx(0.0) + assert result["confusion_matrix"]["overall"]["fd"] == 1 + assert M(f=gt).compare(M(f=pred)) == pytest.approx(0.0) + + def test_two_distinct_objects_do_not_match_on_their_reprs(self): + class M(StructuredModel): + model_config = {"arbitrary_types_allowed": True} + f: Blob = ComparableField() + + assert _readers(M, Blob(), Blob()) == (0.0, 0.0) + + def test_two_int_enum_classes_are_a_mismatch(self): + """An IntEnum member is also an int, so Enum is checked first.""" + + class X(enum.IntEnum): + A = 1 + + class Y(enum.IntEnum): + B = 1 + + class M(StructuredModel): + f: Any = ComparableField() + + assert _readers(M, X.A, Y.B) == (0.0, 0.0) + assert _readers(M, X.A, 1) == (0.0, 0.0) + assert _readers(M, X.A, X.A) == (1.0, 1.0) + + def test_a_decimal_against_a_float_is_a_number_pair(self): + class M(StructuredModel): + f: Union[decimal.Decimal, float] = ComparableField( + comparator=NumericComparator() + ) + + gt = M.model_construct(f=decimal.Decimal("12.5")) + pred = M.model_construct(f=12.5) + assert gt.compare_with(pred)["overall_score"] == pytest.approx(1.0) + assert gt.compare(pred) == pytest.approx(1.0) + + +class TestADeclaredComparatorIsAlwaysCalled: + """The caller chose it for these values; it decides what it can score.""" + + def test_a_bytes_field(self): + class M(StructuredModel): + f: bytes = ComparableField(comparator=BytesEqual()) + + assert _readers(M, b"abc", b"abc") == (1.0, 1.0) + assert _readers(M, b"abc", b"xyz") == (0.0, 0.0) + + def test_a_custom_class(self): + class M(StructuredModel): + model_config = {"arbitrary_types_allowed": True} + f: Point = ComparableField(comparator=PointDistance()) + + compare_with, compare = _readers(M, Point(0, 0), Point(1, 0)) + assert compare_with == pytest.approx(0.9) + assert compare == pytest.approx(0.9) + + def test_a_date_against_its_iso_string(self): + class M(StructuredModel): + f: Union[datetime.date, str] = ComparableField(comparator=DateComparator()) + + assert _readers(M, datetime.date(2026, 9, 14), "2026-09-14") == (1.0, 1.0) + + def test_a_set_reaches_a_set_aware_comparator_as_a_set(self): + """Values arrive as the caller supplied them (#384 review).""" + + class M(StructuredModel): + f: Set[str] = ComparableField( + comparator=Jaccard(), clip_under_threshold=False + ) + + compare_with, compare = _readers(M, {"a", "b"}, {"b", "c"}) + assert compare_with == pytest.approx(1 / 3) + assert compare == pytest.approx(1 / 3) + + def test_the_comparator_receives_the_values_unchanged(self, monkeypatch): + seen = [] + original = ExactComparator.compare + + def spy(self, a, b): + seen.append((a, b)) + return original(self, a, b) + + monkeypatch.setattr(ExactComparator, "compare", spy) + + class M(StructuredModel): + f: Tuple[float, ...] = ComparableField(comparator=ExactComparator()) + + M(f=(3.0, 1.0)).compare_with(M(f=(3.0, 1.0))) + M(f=(3.0, 1.0)).compare(M(f=(3.0, 1.0))) + assert seen == [((3.0, 1.0), (3.0, 1.0))] * 2 + + +class TestTheTwoReadersAgree: + """`compare()` feeds the Hungarian cost matrix, so it must agree (#233).""" + + class X(enum.IntEnum): + A = 1 + + class Y(enum.IntEnum): + B = 1 + + PAIRS = [ + (datetime.date(2026, 9, 14), "2026-09-14"), + (datetime.date(2026, 9, 14), datetime.date(2026, 9, 14)), + (decimal.Decimal("12.5"), 12.5), + (X.A, Y.B), + (X.A, 1), + (Color.RED, Color.RED), + (uuid.UUID(int=1), decimal.Decimal(1)), + (b"abc", b"abc"), + ("text", 3), + ] + + @pytest.mark.parametrize("gt, pred", PAIRS) + @pytest.mark.parametrize( + "comparator", + [None, ExactComparator(), LevenshteinComparator()], + ids=["inferred", "explicit-exact", "explicit-levenshtein"], + ) + def test_compare_matches_compare_with(self, gt, pred, comparator): + # Clipping off, so a partial score is compared raw in both readers. + field = ( + ComparableField(clip_under_threshold=False) + if comparator is None + else ComparableField(comparator=comparator, clip_under_threshold=False) + ) + + class M(StructuredModel): + f: Any = field + + compare_with, compare = _readers(M, gt, pred) + assert compare == pytest.approx(compare_with) + + +@pytest.mark.parametrize("annotation, value, other", CASES, ids=IDS) +def test_scalar_and_list_spellings_agree(annotation, value, other): + """The list path already reached the comparator; the scalar path now does.""" + scalar = _model(annotation, ExactComparator()) + listed = _model(List[annotation], ExactComparator()) + for pred in (value, other): + assert scalar(f=value).compare_with(scalar(f=pred))[ + "overall_score" + ] == pytest.approx( + listed(f=[value]).compare_with(listed(f=[pred]))["overall_score"] + ) + + +@pytest.mark.parametrize("annotation, value, other", CASES, ids=IDS) +def test_reports_show_the_comparator_verdict(annotation, value, other): + M = _model(Optional[annotation], ExactComparator()) + result = M(f=value).compare_with( + M(f=value), document_non_matches=True, document_field_comparisons=True + ) + assert result["non_matches"] == [] + assert [row["match"] for row in result["field_comparisons"]] == [True]