Skip to content

Commit ca00e25

Browse files
docs: explain two-phase flow-sequence handling in sync()
1 parent 05a1797 commit ca00e25

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/yamltrip/document.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,16 @@ def sync(self, *keys: KeyPart, value: Any) -> Document:
468468
except (ValueError, KeyError):
469469
return self.upsert(*normalized, value=value)
470470

471-
# Pre-convert any flow sequences that will be modified.
472-
# This targets only the affected leaf paths, preserving sibling formatting.
471+
# Two-phase flow-sequence handling:
472+
#
473+
# Phase 1 (_flow_seq_replacements) pre-converts only the flow sequences
474+
# that will be modified. A full replace at a higher path would
475+
# re-serialise the whole mapping with 2-space indentation, losing the
476+
# document's existing indent for nested lists.
477+
#
478+
# Phase 2 (except PatchError below) catches cases phase 1 misses. The
479+
# main gap is list reordering: new indices in the diff weren't in the
480+
# original tree, so phase 1 couldn't anticipate them.
473481
doc: Document = self
474482
flow_patches = _flow_seq_replacements(
475483
self._core_doc, old_value, value, normalized

0 commit comments

Comments
 (0)