Skip to content

Commit 038190c

Browse files
author
Michael Brewer
committed
refactor: Broke logic into multiple lines
1 parent 0576dde commit 038190c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

aws_lambda_powertools/utilities/idempotency/persistence/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,14 @@ def _get_hashed_idempotency_key(self, lambda_event: Dict[str, Any]) -> str:
183183

184184
@staticmethod
185185
def is_missing_idempotency_key(data) -> bool:
186-
return data is None or not data or (type(data).__name__ in ("tuple", "list") and all(x is None for x in data))
186+
if data is None:
187+
return True
188+
elif not data:
189+
return True
190+
elif type(data).__name__ in ("tuple", "list", "dict"):
191+
return all(x is None for x in data)
192+
else:
193+
return False
187194

188195
def _get_hashed_payload(self, lambda_event: Dict[str, Any]) -> str:
189196
"""

tests/functional/idempotency/test_idempotency.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,8 @@ def test_is_missing_idempotency_key():
696696
assert BasePersistenceLayer.is_missing_idempotency_key([None, None])
697697
# GIVEN a tuples of Nones THEN is_missing_idempotency_key is True
698698
assert BasePersistenceLayer.is_missing_idempotency_key((None, None))
699+
# GIVEN a dict of Nones THEN is_missing_idempotency_key is True
700+
assert BasePersistenceLayer.is_missing_idempotency_key({None: None})
699701

700702
# GIVEN a str THEN is_missing_idempotency_key is False
701703
assert BasePersistenceLayer.is_missing_idempotency_key("Value") is False

0 commit comments

Comments
 (0)