Currently, sync() raises PatchError when trying to insert into a flow sequence (e.g. repos: []). This forces callers to wrap sync() in a try/except and fall back to upsert():
try:
doc = doc.sync("repos", value=repos_list)
except yamltrip.PatchError:
doc = doc.upsert("repos", value=repos_list)
Proposal: When sync() needs to insert into an empty flow sequence, it should convert the node to a block sequence automatically. An empty flow sequence ([]) has no formatting worth preserving, so this is always the correct thing to do.
For non-empty flow sequences where patching fails, falling back to a full replacement (like upsert) internally would also be reasonable.
This would let callers use sync() unconditionally without needing to handle PatchError.
Currently,
sync()raisesPatchErrorwhen trying to insert into a flow sequence (e.g.repos: []). This forces callers to wrapsync()in a try/except and fall back toupsert():Proposal: When
sync()needs to insert into an empty flow sequence, it should convert the node to a block sequence automatically. An empty flow sequence ([]) has no formatting worth preserving, so this is always the correct thing to do.For non-empty flow sequences where patching fails, falling back to a full replacement (like
upsert) internally would also be reasonable.This would let callers use
sync()unconditionally without needing to handlePatchError.