Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .semversioner/next-release/patch-20260421020145168929.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Add return type hints to generator functions in query/llm/text_utils.py"
}
4 changes: 2 additions & 2 deletions packages/graphrag/graphrag/query/llm/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
logger = logging.getLogger(__name__)


def batched(iterable: Iterator, n: int):
def batched(iterable: Iterator, n: int) -> Iterator[tuple]:
"""
Batch data into tuples of length n. The last batch may be shorter.
Comment on lines +20 to 22
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batched is annotated as returning Iterator[tuple], but tuple is a generic type and leaving it un-parameterized loses most of the downstream type-safety (and may trigger "missing type parameters" warnings in stricter mypy/pyright configs). Since this helper preserves element type, consider making it generic (e.g., T = TypeVar('T')) and typing the signature as iterable: Iterable[T] (or Iterator[T]) with a return of Iterator[tuple[T, ...]] to accurately reflect variable-length batches while keeping element types.

Copilot uses AI. Check for mistakes.

Expand All @@ -32,7 +32,7 @@ def batched(iterable: Iterator, n: int):
yield batch


def chunk_text(text: str, max_tokens: int, tokenizer: Tokenizer | None = None):
def chunk_text(text: str, max_tokens: int, tokenizer: Tokenizer | None = None) -> Iterator[str]:
"""Chunk text by token length."""
if tokenizer is None:
tokenizer = get_tokenizer()
Expand Down