modernize type hints

This commit is contained in:
Matteo Rosati
2026-04-22 17:19:14 +02:00
parent 33b46c2c21
commit 2dfaa68466
8 changed files with 23 additions and 9 deletions
+2
View File
@@ -1 +1,3 @@
from __future__ import annotations
"""Chromy package.""" """Chromy package."""
+7 -3
View File
@@ -60,7 +60,11 @@ def count_collection(collection_name: str) -> int:
return collection.count() return collection.count()
def add_data(collection_name: str, data: list[EmbeddingRecord], file_name: str) -> None: def add_data(
collection_name: str,
data: Sequence[EmbeddingRecord],
file_name: str,
) -> None:
if not data: if not data:
return return
@@ -76,7 +80,7 @@ def add_data(collection_name: str, data: list[EmbeddingRecord], file_name: str)
) )
def query_data(collection_name: str, texts: list[str]) -> QueryResult: def query_data(collection_name: str, texts: Sequence[str]) -> QueryResult:
if not texts: if not texts:
return { return {
"ids": [], "ids": [],
@@ -91,4 +95,4 @@ def query_data(collection_name: str, texts: list[str]) -> QueryResult:
_, collection = _get_client_and_collection(collection_name) _, collection = _get_client_and_collection(collection_name)
return collection.query(query_texts=texts) return collection.query(query_texts=list(texts))
+3 -2
View File
@@ -1,5 +1,6 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Sequence
from typing import TypedDict from typing import TypedDict
from chromadb.utils.embedding_functions import DefaultEmbeddingFunction from chromadb.utils.embedding_functions import DefaultEmbeddingFunction
@@ -10,12 +11,12 @@ class EmbeddingRecord(TypedDict):
embedding: list[float] embedding: list[float]
def embed(chunks: list[str]) -> list[EmbeddingRecord]: def embed(chunks: Sequence[str]) -> list[EmbeddingRecord]:
if not chunks: if not chunks:
return [] return []
embedding_function = DefaultEmbeddingFunction() embedding_function = DefaultEmbeddingFunction()
embeddings = embedding_function(chunks) embeddings = embedding_function(list(chunks))
return [ return [
{ {
+2
View File
@@ -1 +1,3 @@
from __future__ import annotations
"""Command handlers package for the Chroma CLI.""" """Command handlers package for the Chroma CLI."""
+4 -2
View File
@@ -1,4 +1,6 @@
from collections.abc import Mapping from __future__ import annotations
from collections.abc import Mapping, Sequence
from chromadb import QueryResult from chromadb import QueryResult
@@ -7,7 +9,7 @@ from chromy.chunk_functions import chunk_file
from chromy.embed import embed from chromy.embed import embed
def print_lines(lines: list[str]) -> None: def print_lines(lines: Sequence[str]) -> None:
for line in lines: for line in lines:
print(line) print(line)
@@ -1,4 +1,4 @@
# 7. Modernize Type Hints and Add Missing Future Imports # 7. Modernize Type Hints and Add Missing Future Imports [DONE]
## Summary ## Summary
+2
View File
@@ -1 +1,3 @@
from __future__ import annotations
"""Tests for the Chromy CLI.""" """Tests for the Chromy CLI."""
+2 -1
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import io import io
import unittest import unittest
from argparse import Namespace from argparse import Namespace
from collections.abc import Sequence
from contextlib import redirect_stdout from contextlib import redirect_stdout
from chromy.cli_app import build_command_input, execute_command from chromy.cli_app import build_command_input, execute_command
@@ -89,7 +90,7 @@ class BuildCommandInputTests(unittest.TestCase):
self.assertFalse(hasattr(args, "error_message")) self.assertFalse(hasattr(args, "error_message"))
def _parse_input(argv: list[str]) -> object: def _parse_input(argv: Sequence[str]) -> object:
return build_command_input(build_parser().parse_args(argv)) return build_command_input(build_parser().parse_args(argv))