Skip to content

fix: colored view not showing removed items when list is emptied (#575)#586

Open
r266-tech wants to merge 1 commit intoqlustered:masterfrom
r266-tech:fix/colored-view-empty-list
Open

fix: colored view not showing removed items when list is emptied (#575)#586
r266-tech wants to merge 1 commit intoqlustered:masterfrom
r266-tech:fix/colored-view-empty-list

Conversation

@r266-tech
Copy link

Problem

When comparing a list with an empty list using COLORED_VIEW, all removed items are silently dropped from the output. The str() representation returns [] instead of showing the removed items.

Reproduction

from deepdiff.helper import COLORED_VIEW
from deepdiff import DeepDiff

t1 = [1, 2, 3]
t2 = []
print(DeepDiff(t1, t2, view=COLORED_VIEW))  # prints [] instead of showing removed items

Root Cause

In deepdiff/colored_view.py, the list branch of _colorize_json checks if not obj: return '[]' before collecting removed items via self._get_path_removed(path). When t2 is empty, the function returns immediately without ever checking for removed items.

Fix

Move the empty check after collecting removed_map, and only return '[]' if both the object is empty AND there are no removed items.

Testing

  • All 16 existing colored view tests continue to pass
  • Added test_colored_view_list_all_removed to cover the empty list case

Fixes #575

When comparing a list with an empty list using COLORED_VIEW, all
removed items were silently dropped from the output. The empty list
check (if not obj: return '[]') ran before checking for removed items.

Fix: move the empty check after collecting removed_map, and only return
'[]' if both the object is empty AND there are no removed items.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diff of list and empty list is incorrect

1 participant