inveniosoftware / inveniosoftware/dictdiffer

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

Open
#182 1 comment 1 reaction 0 assignees View on GitHub
bug
Dominant language
Python
Stars
849
Forks
99
PR merge metrics
No merged PRs in 30d

Description

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:

```python
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)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.