Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/django/utils/hashable.py: 82%
11 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from django.utils.itercompat import is_iterable
4def make_hashable(value):
5 """
6 Attempt to make value hashable or raise a TypeError if it fails.
8 The returned value should generate the same hash for equal values.
9 """
10 if isinstance(value, dict):
11 return tuple(
12 [
13 (key, make_hashable(nested_value))
14 for key, nested_value in sorted(value.items())
15 ]
16 )
17 # Try hash to avoid converting a hashable iterable (e.g. string, frozenset)
18 # to a tuple.
19 try:
20 hash(value)
21 except TypeError:
22 if is_iterable(value): 22 ↛ 25line 22 didn't jump to line 25, because the condition on line 22 was never false
23 return tuple(map(make_hashable, value))
24 # Non-hashable, non-iterable.
25 raise
26 return value