Skip to content
Myr

Raise TypeError if content is passed a 'dict' instance. (#2495)

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

authored by Tom Christie · committed by GitHub · parent 563a103 · Browse files · 2 files+8 added−1 removed
This commit

State

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

Diff stats

2 files+8 added−1 removed

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

2 files+8 added−1 removed

modified:httpx/_content.py+5 added-1 removed
112 unmodified lines
113 content_length = len(body)114 headers = {"Content-Length": str(content_length)} if body else {}115 return headers, ByteStream(body)116117 elif isinstance(content, Iterable):117 elif isinstance(content, Iterable) and not isinstance(content, dict):118 # `not isinstance(content, dict)` is a bit oddly specific, but it119 # catches a case that's easy for users to make in error, and would120 # otherwise pass through here, like any other bytes-iterable,121 # because `dict` happens to be iterable. See issue #2491.122 content_length_or_none = peek_filelike_length(content)123124 if content_length_or_none is None:125 headers = {"Transfer-Encoding": "chunked"}
114 unmodified lines
modified:tests/test_content.py+3 added
358 unmodified lines
359def test_invalid_argument():360 with pytest.raises(TypeError):361 httpx.Request(method, url, content=123) # type: ignore362363 with pytest.raises(TypeError):364 httpx.Request(method, url, content={"a": "b"}) # type: ignore365366367@pytest.mark.asyncio368async def test_multipart_multiple_files_single_input_content():369 files = [370 ("file", io.BytesIO(b"<file content 1>")),
116 unmodified lines