From b21a8b1f51c36a337019dd0077f72e63c0f82352 Mon Sep 17 00:00:00 2001 From: Nachiket Date: Sat, 6 Jun 2026 03:24:31 -0700 Subject: [PATCH] fix: omit empty comma array query params --- src/anthropic/_qs.py | 10 ++++------ tests/test_qs.py | 3 +++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/anthropic/_qs.py b/src/anthropic/_qs.py index 4127c19c6..d8cedf44d 100644 --- a/src/anthropic/_qs.py +++ b/src/anthropic/_qs.py @@ -85,12 +85,10 @@ def _stringify_item( if isinstance(value, (list, tuple)): array_format = opts.array_format if array_format == "comma": - return [ - ( - key, - ",".join(self._primitive_value_to_str(item) for item in value if item is not None), - ), - ] + serialised = ",".join(self._primitive_value_to_str(item) for item in value if item is not None) + if not serialised: + return [] + return [(key, serialised)] elif array_format == "repeat": items = [] for item in value: diff --git a/tests/test_qs.py b/tests/test_qs.py index 564a41e61..5b0845e26 100644 --- a/tests/test_qs.py +++ b/tests/test_qs.py @@ -52,6 +52,9 @@ def test_array_comma(method: str) -> None: assert unquote(serialise({"in": ["foo", "bar"]})) == "in=foo,bar" assert unquote(serialise({"a": {"b": [True, False]}})) == "a[b]=true,false" assert unquote(serialise({"a": {"b": [True, False, None, True]}})) == "a[b]=true,false,true" + assert unquote(serialise({"a": []})) == "" + assert unquote(serialise({"a": [None]})) == "" + assert unquote(serialise({"a": {"b": []}})) == "" def test_array_repeat() -> None: