Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 686429e

Browse files
jbogusciakJozef Volak
andauthored
Fix util conditions (#57)
* Update conditions Signed-off-by: Jakub Boguščiak <jakub.bogusciak@elisapolystar.com> * Disable ruff check on conditions Signed-off-by: Jakub Boguščiak <jakub.bogusciak@elisapolystar.com> * Refactor is input valid functionality --------- Signed-off-by: Jakub Boguščiak <jakub.bogusciak@elisapolystar.com> Co-authored-by: Jozef Volak <jvolak@frinx.io>
1 parent 4c3554a commit 686429e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

frinx/common/util.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def normalize_base_url(url: str) -> str:
4848
return url.removesuffix('/')
4949

5050

51+
def is_input_valid(item: Any) -> Any:
52+
"""An item is considered valid if it is not None and not an empty string."""
53+
return item is not None and item != '' # noqa PLC1901
54+
55+
5156
def remove_empty_elements_from_root_dict(any_dict: DictAny) -> DictAny:
5257
"""
5358
Removes empty elements (None, empty dictionaries, or empty lists) from a dictionary root.
@@ -58,7 +63,7 @@ def remove_empty_elements_from_root_dict(any_dict: DictAny) -> DictAny:
5863
Returns:
5964
Dict[str, Any]: A new dictionary with empty elements removed.
6065
"""
61-
return dict((k, v) for k, v in any_dict.items() if v is not None and v)
66+
return dict((k, v) for k, v in any_dict.items() if is_input_valid(v))
6267

6368

6469
def remove_empty_elements_from_dict(any_dict: DictAny) -> Any:
@@ -78,9 +83,9 @@ def recursive_cleanup(d: DictAny) -> Any:
7883
case dict():
7984
cleaned[k] = recursive_cleanup(v)
8085
case list():
81-
cleaned[k] = [item for item in v if item is not None and item]
86+
cleaned[k] = [item for item in v if item]
8287
case _:
83-
if v is not None and v:
88+
if is_input_valid(v):
8489
cleaned[k] = v
8590
return cleaned
8691
return recursive_cleanup(any_dict)

0 commit comments

Comments
 (0)