Skip to content

Commit 4df18cc

Browse files
committed
allow filter_bubble_uids to safely handle mixed-type iterables
1 parent 93df3c3 commit 4df18cc

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/bubble_data_api_client/validation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88

99

1010
def is_bubble_uid(value: Any) -> bool:
11-
"""Check if a string matches the Bubble UID format (e.g., '1767090310181x452059685440531200')."""
12-
if not isinstance(value, str):
13-
return False
14-
return _BUBBLE_UID_PATTERN.fullmatch(value) is not None
11+
"""Check if a value is a valid Bubble UID (e.g., '1767090310181x452059685440531200')."""
12+
return isinstance(value, str) and _BUBBLE_UID_PATTERN.fullmatch(value) is not None
1513

1614

17-
def filter_bubble_uids(values: Iterable[str]) -> list[str]:
18-
"""Return only valid Bubble UIDs from an iterable, filtering out invalid ones."""
15+
def filter_bubble_uids(values: Iterable[Any]) -> list[str]:
16+
"""Return only valid Bubble UIDs from an iterable, filtering out invalid values."""
1917
return [v for v in values if is_bubble_uid(v)]

src/tests/unit/test_validation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,9 @@ def test_filter_bubble_uids_accepts_iterator() -> None:
100100
"""Should work with any iterable, not just lists."""
101101
values = iter(["1x2", "invalid", "3x4"])
102102
assert filter_bubble_uids(values) == ["1x2", "3x4"]
103+
104+
105+
def test_filter_bubble_uids_non_string_values() -> None:
106+
"""Non-string values should be filtered out."""
107+
values = ["1x2", None, 123, "3x4", {"uid": "5x6"}, True, "7x8"]
108+
assert filter_bubble_uids(values) == ["1x2", "3x4", "7x8"]

0 commit comments

Comments
 (0)