Widen chunk() type to accept None, add test for None guard

This commit is contained in:
Chris McDonough 2026-06-22 14:24:12 -04:00
parent 21a8f52893
commit 633517bf04
4 changed files with 10 additions and 3 deletions

View file

@ -15,7 +15,7 @@ class DocumentChunker(ABC):
"""
@abstractmethod
async def chunk(self, document: "DoclingDocument") -> list["Chunk"]:
async def chunk(self, document: "DoclingDocument | None") -> list["Chunk"]:
"""Split a document into chunks with metadata.
Args:

View file

@ -162,7 +162,7 @@ class DoclingLocalChunker(DocumentChunker):
return result
async def chunk(self, document: "DoclingDocument") -> list[Chunk]:
async def chunk(self, document: "DoclingDocument | None") -> list[Chunk]:
"""Split the document into chunks with metadata.
Extracts structured metadata from each DocChunk including:

View file

@ -129,7 +129,7 @@ class DoclingServeChunker(DocumentChunker):
return result.get("chunks", [])
async def chunk(self, document: "DoclingDocument") -> list[Chunk]:
async def chunk(self, document: "DoclingDocument | None") -> list[Chunk]:
"""Split the document into chunks with metadata via docling-serve.
Extracts structured metadata from the API response including:

View file

@ -55,6 +55,13 @@ async def test_local_chunker(qa_corpus: list[dict[str, str]]):
assert abs(total_tokens - original_tokens) <= original_tokens * 0.1
@pytest.mark.asyncio
async def test_local_chunker_none_document():
"""Test DoclingLocalChunker returns empty list for None document."""
chunker = DoclingLocalChunker()
assert await chunker.chunk(None) == []
@pytest.mark.asyncio
async def test_local_chunker_runs_off_event_loop_thread():
"""Chunking is CPU-bound; verify it runs in a worker thread."""