From 08901009255b95b7500f2a19f6695f9983e581ae Mon Sep 17 00:00:00 2001 From: Cognis Digital Date: Sat, 25 Jul 2026 00:01:54 -0400 Subject: [PATCH] Fix nonexistent iter_content() reference in httpcore.stream() docstring The docstring for httpcore.stream() tells users to read a streamed body with "for chunk in response.iter_content()", but Response has no iter_content() method -- the streaming method is iter_stream(). Running the documented snippet raises AttributeError. Correct it to iter_stream() and add a regression test pinning the documented streaming method names, since doctests are not run in CI. --- httpcore/_api.py | 2 +- tests/test_models.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/httpcore/_api.py b/httpcore/_api.py index 38b961d1..b76683cc 100644 --- a/httpcore/_api.py +++ b/httpcore/_api.py @@ -66,7 +66,7 @@ def stream( When using the `stream()` function, the body of the response will not be automatically read. If you want to access the response body you should - either use `content = response.read()`, or `for chunk in response.iter_content()`. + either use `content = response.read()`, or `for chunk in response.iter_stream()`. Arguments: method: The HTTP method for the request. Typically one of `"GET"`, diff --git a/tests/test_models.py b/tests/test_models.py index 7dd6e419..c11149e1 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -117,6 +117,19 @@ def test_response(): assert repr(response.stream) == "" +def test_response_streaming_api_names(): + # The public docstrings (e.g. `httpcore.stream()`) tell users to read a + # streamed body with `response.read()` or `for chunk in response.iter_stream()`. + # Pin those method names so the documented API cannot silently drift to a + # name that does not exist (doctests are not run in CI). + response = httpcore.Response(200) + assert hasattr(response, "read") + assert hasattr(response, "iter_stream") + assert hasattr(response, "aread") + assert hasattr(response, "aiter_stream") + assert not hasattr(response, "iter_content") + + # Tests for reading and streaming sync byte streams...