Skip to content

sync() should handle flow sequences gracefully #31

Description

@nathanjmcdougall

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions