Skip to content

Commit bb9d7cf

Browse files
fix(responses): improve type annotations in AsyncResponses.wait_until_completed
- Use Optional[List[ResponseIncludable]] for include - Pass omit when include is None to satisfy type checker - Explicitly cast resp to Response to silence Pyright errors - Ensure static type safety and pass all lints
1 parent 78295cb commit bb9d7cf

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/openai/resources/responses/responses.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,9 +1497,9 @@ async def wait_until_completed(
14971497
*,
14981498
poll_interval: float = 1.0,
14991499
timeout: float = 60.0,
1500-
include: list = None,
1501-
**kwargs
1502-
) -> "Response":
1500+
include: Optional[List[ResponseIncludable]] = None,
1501+
**kwargs: Any,
1502+
) -> Response:
15031503
"""
15041504
Polls retrieve() until the response status is 'completed' or timeout is reached.
15051505
Args:
@@ -1513,16 +1513,20 @@ async def wait_until_completed(
15131513
Raises:
15141514
TimeoutError: If the response does not complete in time.
15151515
"""
1516-
import asyncio
15171516
import time
1518-
start = time.monotonic()
1517+
import asyncio
1518+
1519+
start: float = time.monotonic()
15191520
while True:
1520-
resp = await self.retrieve(response_id, include=include, **kwargs)
1521-
if hasattr(resp, "status") and resp.status == "completed":
1521+
resp = cast(
1522+
Response, await self.retrieve(response_id, include=include if include is not None else omit, **kwargs)
1523+
)
1524+
if hasattr(resp, "status") and getattr(resp, "status", None) == "completed":
15221525
return resp
15231526
if time.monotonic() - start > timeout:
15241527
raise TimeoutError(f"Response {response_id} did not complete within {timeout} seconds.")
15251528
await asyncio.sleep(poll_interval)
1529+
15261530
@cached_property
15271531
def input_items(self) -> AsyncInputItems:
15281532
return AsyncInputItems(self._client)

0 commit comments

Comments
 (0)