Coverage for src/objectstate/value_semantics.py: 88%
17 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-17 07:22 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-17 07:22 +0000
1"""Shared value comparison semantics for declaration and state reconciliation."""
3from __future__ import annotations
5from collections.abc import Mapping, Sequence
8def semantic_values_equal(left: object, right: object) -> bool:
9 """Compare nested values without requiring hashability or scalar equality."""
11 if left is right:
12 return True
13 if isinstance(left, Mapping) and isinstance(right, Mapping):
14 return left.keys() == right.keys() and all(
15 semantic_values_equal(left[key], right[key]) for key in left
16 )
17 if (
18 isinstance(left, Sequence)
19 and isinstance(right, Sequence)
20 and not isinstance(left, (str, bytes, bytearray))
21 and not isinstance(right, (str, bytes, bytearray))
22 ):
23 return len(left) == len(right) and all(
24 semantic_values_equal(left_value, right_value)
25 for left_value, right_value in zip(left, right)
26 )
27 try:
28 comparison = left == right
29 except Exception:
30 return False
31 try:
32 return bool(comparison)
33 except (TypeError, ValueError):
34 return False