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
5 changes: 2 additions & 3 deletions src/openai/_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +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 []
return [(key, serialised)]
return [(key, self._primitive_value_to_str(value))]

def _primitive_value_to_str(self, value: PrimitiveData) -> str:
# copied from httpx
Expand Down
8 changes: 8 additions & 0 deletions tests/test_qs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def test_basic() -> None:
assert stringify({"a": None}) == ""


def test_empty_string_scalar_is_kept_distinct_from_none() -> None:
# An explicit empty string is a real value ("a=") and must not be
# conflated with omitting the key entirely (None).
assert unquote(stringify({"a": ""})) == "a="
assert stringify({"a": None}) == ""
assert unquote(stringify({"a": "", "b": 1})) == "a=&b=1"


@pytest.mark.parametrize("method", ["class", "function"])
def test_nested_dotted(method: str) -> None:
if method == "class":
Expand Down