Skip to content
Myr

Raise `TypeError` on invalid query params. (#2523)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Raise TypeError on invalid query params * Fix TypeError * Update tests/models/test_queryparams.py Co-authored-by: Michael Adkins <contact@zanie.dev> * Linting * Fix exception check

authored by Tom Christie · committed by GitHub · parent 10a3b68 · Browse files · 2 files+12 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Michael Adkins <contact@zanie.dev>

Diff stats

2 files+12 added−1 removed

  • tests:+7 added−0 removed
  • other:+5 added−1 removed

2 files+12 added−1 removed

modified:httpx/_utils.py+5 added-1 removed
65 unmodified lines
66 elif value is False:67 return "false"68 elif value is None:69 return ""70 elif isinstance(value, (str, float, int)):70 return str(value)71 return str(value)72 raise TypeError(73 f"Expected str, int, float, bool, or None. Got {type(value).__name__!r}."74 )757677def is_known_encoding(encoding: str) -> bool:78 """
455 unmodified lines
modified:tests/models/test_queryparams.py+7 added
85 unmodified lines
86 q = httpx.QueryParams("a")87 assert str(q) == "a="888990def test_invalid_query_params():91 with pytest.raises(92 TypeError, match=r"Expected str, int, float, bool, or None. Got 'bytes'."93 ):94 httpx.QueryParams({"a": b"bytes"})959697def test_queryparam_update_is_hard_deprecated():98 q = httpx.QueryParams("a=123")99 with pytest.raises(RuntimeError):100 q.update({"a": "456"})
43 unmodified lines