diff --git a/src/anthropic/_qs.py b/src/anthropic/_qs.py index 4127c19c..d8cedf44 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 564a41e6..5b0845e2 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: