From 5171eebbc12d398748807a7675aeb469363d0f2b Mon Sep 17 00:00:00 2001 From: Bryant Gray Date: Thu, 11 Jan 2024 16:31:16 +0000 Subject: [PATCH] Handle `None` in `HashableDict` --- tap_mambu/helpers/hashable_dict.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tap_mambu/helpers/hashable_dict.py b/tap_mambu/helpers/hashable_dict.py index 9100152..66dd0cb 100644 --- a/tap_mambu/helpers/hashable_dict.py +++ b/tap_mambu/helpers/hashable_dict.py @@ -1,7 +1,3 @@ -import json -import math - - class HashableDict(dict): @staticmethod @@ -9,7 +5,11 @@ 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):