Skip to content

Removing an item from a list causes a cascade of "changes", rather than "removes" #182

@leodking

Description

@leodking

Package version (if known): 0.8.1

I try diffing two YAML files - in the second one, I've removed a single item from the list. Ideally I would like to see this as a remove diff. Instead I get:

[('change', ['targ1', 0], ('one', 'two')), ('change', ['targ1', 1], ('two', 'three')), ('remove', 'targ1', [(2, 'three')])]

So basically it thinks I've changed "one" to "two", "two" to "three", and then removed "three".

It works if I remove an item from the end of a list, but I can't guarantee that this will be the case. I'm using ruamel.yaml to load the dicts from YAML

Test code:

from dictdiffer import diff as dictdiff
from ruamel import yaml

first = """
targ1:
    - one
    - two
    - three

"""

second = """
targ1:
    - two
    - three
"""

first_d = yaml.load(first, Loader=yaml.Loader)
second_d = yaml.load(second, Loader=yaml.Loader)

res = dictdiff(first_d, second_d)
diffs = list(res)
print(diffs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions