Skip to content

Commit ffd4ee7

Browse files
committed
fix: replace Iterator/AsyncIterator with Generator/AsyncGenerator on all generator functions
Every function annotated -> Iterator[T] or -> AsyncIterator[T] that contains a yield statement is actually a generator function, not a plain function that returns an iterator. The correct annotations are: sync yield -> Generator[YieldType, SendType, ReturnType] async yield -> AsyncGenerator[YieldType, SendType] The previous async fix (Iterator -> AsyncGenerator) was applied inconsistently: the same issue existed on all sync counterparts and was left behind. This commit fixes all remaining sites for full consistency: base_client.py: uipath_stream Iterator[str | bytes] -> Generator[str | bytes, None, None] _stream Iterator[ChatGenerationChunk] -> Generator[ChatGenerationChunk, None, None] _uipath_stream Iterator[ChatGenerationChunk] -> Generator[ChatGenerationChunk, None, None] clients/normalized/chat_models.py: _uipath_stream Iterator[ChatGenerationChunk] -> Generator[ChatGenerationChunk, None, None] clients/bedrock/utils.py: _stream_generator Iterator[dict[str, Any]] -> Generator[dict[str, Any], None, None] Added Generator to collections.abc imports in all three files.
1 parent 1ae8f0b commit ffd4ee7

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

packages/uipath_langchain_client/src/uipath_langchain_client/base_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import logging
2727
from abc import ABC
28-
from collections.abc import AsyncGenerator, AsyncIterator, Iterator, Mapping, Sequence
28+
from collections.abc import AsyncGenerator, AsyncIterator, Generator, Iterator, Mapping, Sequence
2929
from functools import cached_property
3030
from typing import Any, Literal
3131

@@ -239,7 +239,7 @@ def uipath_stream(
239239
stream_type: Literal["text", "bytes", "lines", "raw"] = "lines",
240240
raise_status_error: bool = False,
241241
**kwargs: Any,
242-
) -> Iterator[str | bytes]:
242+
) -> Generator[str | bytes, None, None]:
243243
"""Make a synchronous streaming HTTP request to the UiPath API.
244244
245245
Args:
@@ -393,7 +393,7 @@ def _stream(
393393
stop: list[str] | None = None,
394394
run_manager: CallbackManagerForLLMRun | None = None,
395395
**kwargs: Any,
396-
) -> Iterator[ChatGenerationChunk]:
396+
) -> Generator[ChatGenerationChunk, None, None]:
397397
set_captured_response_headers({})
398398
try:
399399
first = True
@@ -413,7 +413,7 @@ def _uipath_stream(
413413
stop: list[str] | None = None,
414414
run_manager: CallbackManagerForLLMRun | None = None,
415415
**kwargs: Any,
416-
) -> Iterator[ChatGenerationChunk]:
416+
) -> Generator[ChatGenerationChunk, None, None]:
417417
"""Override in subclasses to provide the core (non-wrapped) stream logic."""
418418
yield from super()._stream(messages, stop=stop, run_manager=run_manager, **kwargs)
419419

packages/uipath_langchain_client/src/uipath_langchain_client/clients/bedrock/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import json
3-
from typing import Any, Iterator
3+
from typing import Any
4+
from collections.abc import Generator, Iterator
45

56
from httpx import Client
67

@@ -50,7 +51,7 @@ def __init__(self, httpx_client: Client | None = None, region_name: str = "PLACE
5051
self.httpx_client = httpx_client
5152
self.meta = _MockClientMeta(region_name=region_name)
5253

53-
def _stream_generator(self, request_body: dict[str, Any]) -> Iterator[dict[str, Any]]:
54+
def _stream_generator(self, request_body: dict[str, Any]) -> Generator[dict[str, Any], None, None]:
5455
if self.httpx_client is None:
5556
raise ValueError("httpx_client is not set")
5657
with self.httpx_client.stream("POST", "/", json=_serialize_bytes(request_body)) as response:

packages/uipath_langchain_client/src/uipath_langchain_client/clients/normalized/chat_models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""
2525

2626
import json
27-
from collections.abc import AsyncGenerator, AsyncIterator, Callable, Iterator, Sequence
27+
from collections.abc import AsyncGenerator, Callable, Generator, Iterator, Sequence
2828
from typing import Any
2929

3030
from langchain_core.callbacks import (
@@ -392,15 +392,15 @@ def _uipath_stream(
392392
stop: list[str] | None = None,
393393
run_manager: CallbackManagerForLLMRun | None = None,
394394
**kwargs: Any,
395-
) -> Iterator[ChatGenerationChunk]:
395+
) -> Generator[ChatGenerationChunk, None, None]:
396396
request_body = self._preprocess_request(messages, stop=stop, **kwargs)
397397
request_body["stream"] = True
398398
for chunk in self.uipath_stream(
399399
request_body=request_body, stream_type="lines", raise_status_error=True
400400
):
401401
chunk = str(chunk)
402402
if chunk.startswith("data:"):
403-
chunk = chunk[len("data:"):].strip()
403+
chunk = chunk[len("data:") :].strip()
404404
try:
405405
json_data = json.loads(chunk)
406406
except json.JSONDecodeError:
@@ -423,7 +423,7 @@ async def _uipath_astream(
423423
):
424424
chunk = str(chunk)
425425
if chunk.startswith("data:"):
426-
chunk = chunk[len("data:"):].strip()
426+
chunk = chunk[len("data:") :].strip()
427427
try:
428428
json_data = json.loads(chunk)
429429
except json.JSONDecodeError:

0 commit comments

Comments
 (0)