Skip to content

Commit

Permalink
Handle None in HashableDict
Browse files Browse the repository at this point in the history
  • Loading branch information
bryantgray committed Jan 11, 2024
1 parent d51282c commit 5171eeb
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions tap_mambu/helpers/hashable_dict.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import json
import math


class HashableDict(dict):

@staticmethod
def _recur_hash(value):
if type(value) in [dict, HashableDict]:
return HashableDict(value).__key()
if type(value) == list:
return tuple(sorted(map(HashableDict._recur_hash, value), key=lambda x: x if x is not None else -math.inf))
# None values are not sortable, but they are appended to the end of
# the list so that they are still hashed
sortable_values = [x for x in map(HashableDict._recur_hash, value) if x is not None]
none_values = [x for x in map(HashableDict._recur_hash, value) if x is None]
return tuple(sorted(sortable_values) + none_values)
return value

def __key(self):
Expand Down

0 comments on commit 5171eeb

Please sign in to comment.