Skip to content

Commit b2fcd65

Browse files
author
Bobby Morck
committed
Update docs and rename to ignore_iterable_order
1 parent b769cae commit b2fcd65

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

deepdiff/deephash.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def __init__(self,
144144
parent="root",
145145
encodings=None,
146146
ignore_encoding_errors=False,
147-
ignore_list_order=True,
147+
ignore_iterable_order=True,
148148
**kwargs):
149149
if kwargs:
150150
raise ValueError(
@@ -191,7 +191,7 @@ def __init__(self,
191191
self.ignore_private_variables = ignore_private_variables
192192
self.encodings = encodings
193193
self.ignore_encoding_errors = ignore_encoding_errors
194-
self.ignore_list_order = ignore_list_order
194+
self.ignore_iterable_order = ignore_iterable_order
195195

196196
self._hash(obj, parent=parent, parents_ids=frozenset({get_id(obj)}))
197197

@@ -427,7 +427,7 @@ def _prep_iterable(self, obj, parent, parents_ids=EMPTY_FROZENSET):
427427
]
428428

429429
result = map(str, result) # making sure the result items are string so join command works.
430-
if self.ignore_list_order:
430+
if self.ignore_iterable_order:
431431
result = sorted(result)
432432
result = ','.join(result)
433433
result = KEY_TO_VAL_STR.format(type(obj).__name__, result)

docs/deephash_doc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ ignore_private_variables: Boolean, default = True
123123
ignore_encoding_errors: Boolean, default = False
124124
If you want to get away with UnicodeDecodeError without passing explicit character encodings, set this option to True. If you want to make sure the encoding is done properly, keep this as False and instead pass an explicit list of character encodings to be considered via the encodings parameter.
125125

126+
ignore_iterable_order: Boolean, default = True
127+
If order of items in an iterable should not cause the hash of the iterable to be different.
126128

127129
number_format_notation : string, default="f"
128130
number_format_notation is what defines the meaning of significant digits. The default value of "f" means the digits AFTER the decimal point. "f" stands for fixed point. The other option is "e" which stands for exponent notation or scientific notation.

tests/test_hash.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def test_same_sets_same_hash(self):
369369

370370
assert t1_hash[get_id(t1)] == t2_hash[get_id(t2)]
371371

372-
@pytest.mark.parametrize("list1, list2, ignore_list_order, is_equal", [
372+
@pytest.mark.parametrize("list1, list2, ignore_iterable_order, is_equal", [
373373
([1, 2], [2, 1], False, False),
374374
([1, 2], [2, 1], True, True),
375375
([1, 2, 3], [1, 3, 2], False, False),
@@ -378,9 +378,9 @@ def test_same_sets_same_hash(self):
378378
((1, 2), (2, 1), False, False),
379379
((1, 2), (2, 1), True, True),
380380
])
381-
def test_list_ignore_order(self, list1, list2, ignore_list_order, is_equal):
382-
list1_hash = DeepHash(list1, ignore_list_order=ignore_list_order)
383-
list2_hash = DeepHash(list2, ignore_list_order=ignore_list_order)
381+
def test_ignore_iterable_order(self, list1, list2, ignore_iterable_order, is_equal):
382+
list1_hash = DeepHash(list1, ignore_iterable_order=ignore_iterable_order)
383+
list2_hash = DeepHash(list2, ignore_iterable_order=ignore_iterable_order)
384384

385385
assert is_equal == (list1_hash[list1] == list2_hash[list2])
386386

0 commit comments

Comments
 (0)