โ† oracle_full

fastapi_15023

resolved RESOLVED UNSUBMITTED PASS ยท None tool calls ยท 0 s ยท fastapi/fastapi

Task input

๐Ÿ“ Update docs for responses and new stream with `yield`

๐Ÿ“ Update docs for responses and new stream with `yield`

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/docs_src/stream_data/tutorial002_py310.py
+++ b/docs_src/stream_data/tutorial002_py310.py
@@ -22,23 +22,33 @@ class PNGStreamingResponse(StreamingResponse):
 
 @app.get("/image/stream", response_class=PNGStreamingResponse)
 async def stream_image() -> AsyncIterable[bytes]:
-    for chunk in read_image():
-        yield chunk
+    with read_image() as image_file:
+        for chunk in image_file:
+            yield chunk
 
 
 @app.get("/image/stream-no-async", response_class=PNGStreamingResponse)
 def stream_image_no_async() -> Iterable[bytes]:
-    for chunk in read_image():
-        yield chunk
+    with read_image() as image_file:
+        for chunk in image_file:
+            yield chunk
+
+
+@app.get("/image/stream-no-async-yield-from", response_class=PNGStreamingResponse)
+def stream_image_no_async_yield_from() -> Iterable[bytes]:
+    with read_image() as image_file:
+        yield from image_file
 
 
 @app.get("/image/stream-no-annotation", response_class=PNGStreamingResponse)
 async def stream_image_no_annotation():
-    for chunk in read_image():
-        yield chunk
+    with read_image() as image_file:
+        for chunk in image_file:
+            yield chunk
 
 
 @app.get("/image/stream-no-async-no-annotation", response_class=PNGStreamingResponse)
 def stream_image_no_async_no_annotation():
-    for chunk in read_image():
-        yield chunk
+    with read_image() as image_file:
+        for chunk in image_file:
+            yield chunk

Test output

show
......                                                                   [100%]
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-1.6.0-py3-none-any/starlette/testclient.py:53
  /Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-1.6.0-py3-none-any/starlette/testclient.py:53: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
    _PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
6 passed, 1 warning in 0.46s