Skip to content

Conversation

@yannrouillard
Copy link

Summary

Fixes a bug where COLORED_VIEW and COLORED_COMPACT_VIEW would display an empty list [] instead of showing removed items in red when all list items are removed.

Problem

When all items are removed from a list (t2 becomes empty), the colored view displays [] instead of the removed items in red.

Root Cause

In colored_view.py, _colorize_json() returned '[]' immediately when the list was empty, without checking for removed items.

Solution

Check for removed items before returning empty list representation.

Changes

  • deepdiff/colored_view.py: Fixed early return logic
  • tests/test_colored_view.py: Added 2 test cases

Testing

All 18 tests pass including 2 new tests for this bug.

@yannrouillard yannrouillard force-pushed the fix/colored-view-empty-list-display branch from 8dcb758 to e04f309 Compare November 5, 2025 18:37
When comparing two lists where all items are removed (t2 becomes an empty list),
the colored view would display an empty list [] instead of showing the removed
items in red.

The bug occurred because `_colorize_json()` returned '[]' immediately if the
list was empty, without checking for items that were removed and should be
displayed.

Fix: Check for removed items before returning empty list representation.

Added tests:
- test_colored_view_list_all_items_removed
- test_colored_compact_view_list_all_items_removed
@yannrouillard yannrouillard force-pushed the fix/colored-view-empty-list-display branch from a32af48 to e7da467 Compare November 5, 2025 18:42
@yannrouillard yannrouillard marked this pull request as ready for review November 5, 2025 18:42
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.

1 participant