Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deepdiff/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ def stringify_param(self, force: Optional[str] = None) -> Optional[str]:
else:
result = candidate if resurrected == param else None

if result is None and force == 'yes':
result = '(unrepresentable)'

if result:
result = ':' if self.param_repr_format is None else self.param_repr_format.format(result)

Expand Down
21 changes: 21 additions & 0 deletions tests/test_diff_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ def test_non_subscriptable_iterable_path(self):
assert change.path(force='yes') == 'root(unrepresentable)'
assert change.path(force='fake') == 'root[2]'

def test_unrepresentable_dict_key_path(self):
class Id:
def __repr__(self):
return '<id>'

def __hash__(self):
return 1

def __eq__(self, other):
return isinstance(other, Id)

key = Id()
t1 = {key: 10}
t2 = {key: 20}
ddiff = DeepDiff(t1, t2, view='tree')
(change, ) = ddiff['values_changed']

# repr does not round-trip, so there is no parsable path
assert change.path() is None
assert change.path(force='yes') == 'root[(unrepresentable)]'

def test_report_type_in_iterable(self):
a = {"temp": ["a"]}
b = {"temp": ["b"]}
Expand Down