Normalizes a value for stable equality. * Tuples become lists (OTel coerces sequences to tuples on attributes). * Enums become their ``.value``. * Dict entries whose value is ``None`` are dropped (these are inserted by pydantic ``model_dump`` for unset fields and would dominate diffs).
(value: object)
| 254 | |
| 255 | |
| 256 | def _normalize(value: object) -> object: |
| 257 | """Normalizes a value for stable equality. |
| 258 | |
| 259 | * Tuples become lists (OTel coerces sequences to tuples on attributes). |
| 260 | * Enums become their ``.value``. |
| 261 | * Dict entries whose value is ``None`` are dropped (these are inserted by |
| 262 | pydantic ``model_dump`` for unset fields and would dominate diffs). |
| 263 | """ |
| 264 | if isinstance(value, Enum): |
| 265 | return value.value |
| 266 | if isinstance(value, tuple): |
| 267 | return [_normalize(v) for v in value] |
| 268 | if isinstance(value, list): |
| 269 | return [_normalize(v) for v in value] |
| 270 | if isinstance(value, dict): |
| 271 | return {k: _normalize(v) for k, v in value.items() if v is not None} |
| 272 | return value |
| 273 | |
| 274 | |
| 275 | # --------------------------------------------------------------------------- |