Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/anthropic/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def _stringify_item(
f"Unknown array_format value: {array_format}, choose from {', '.join(get_args(ArrayFormat))}"
)

serialised = self._primitive_value_to_str(value)
if not serialised:
if value is None:
return []
serialised = self._primitive_value_to_str(value)
return [(key, serialised)]

def _primitive_value_to_str(self, value: PrimitiveData) -> str:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_basic() -> None:
assert stringify({"a": False}) == "a=false"
assert stringify({"a": 1.23456}) == "a=1.23456"
assert stringify({"a": None}) == ""
assert stringify({"a": ""}) == "a="


@pytest.mark.parametrize("method", ["class", "function"])
Expand All @@ -40,6 +41,7 @@ def test_nested_brackets() -> None:
assert unquote(stringify({"a": {"b": "c", "d": "e", "f": "g"}})) == "a[b]=c&a[d]=e&a[f]=g"
assert unquote(stringify({"a": {"b": {"c": {"d": "e"}}}})) == "a[b][c][d]=e"
assert unquote(stringify({"a": {"b": True}})) == "a[b]=true"
assert unquote(stringify({"a": {"b": ""}})) == "a[b]="


@pytest.mark.parametrize("method", ["class", "function"])
Expand All @@ -58,6 +60,7 @@ def test_array_repeat() -> None:
assert unquote(stringify({"in": ["foo", "bar"]})) == "in=foo&in=bar"
assert unquote(stringify({"a": {"b": [True, False]}})) == "a[b]=true&a[b]=false"
assert unquote(stringify({"a": {"b": [True, False, None, True]}})) == "a[b]=true&a[b]=false&a[b]=true"
assert unquote(stringify({"a": {"b": ["", None, "c"]}})) == "a[b]=&a[b]=c"
assert unquote(stringify({"in": ["foo", {"b": {"c": ["d", "e"]}}]})) == "in=foo&in[b][c]=d&in[b][c]=e"


Expand Down