You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hashable.py 541B

5 years ago
12345678910111213141516171819
  1. from django.utils.itercompat import is_iterable
  2. def make_hashable(value):
  3. if isinstance(value, dict):
  4. return tuple([
  5. (key, make_hashable(nested_value))
  6. for key, nested_value in value.items()
  7. ])
  8. # Try hash to avoid converting a hashable iterable (e.g. string, frozenset)
  9. # to a tuple.
  10. try:
  11. hash(value)
  12. except TypeError:
  13. if is_iterable(value):
  14. return tuple(map(make_hashable, value))
  15. # Non-hashable, non-iterable.
  16. raise
  17. return value