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."""
+7 -3
View File
@@ -60,7 +60,11 @@ def count_collection(collection_name: str) -> int:
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:
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:
return {
"ids": [],
@@ -91,4 +95,4 @@ def query_data(collection_name: str, texts: list[str]) -> QueryResult:
_, 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 collections.abc import Sequence
from typing import TypedDict
from chromadb.utils.embedding_functions import DefaultEmbeddingFunction
@@ -10,12 +11,12 @@ class EmbeddingRecord(TypedDict):
embedding: list[float]
def embed(chunks: list[str]) -> list[EmbeddingRecord]:
def embed(chunks: Sequence[str]) -> list[EmbeddingRecord]:
if not chunks:
return []
embedding_function = DefaultEmbeddingFunction()
embeddings = embedding_function(chunks)
embeddings = embedding_function(list(chunks))
return [
{
+2
View File
@@ -1 +1,3 @@
from __future__ import annotations
"""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
@@ -7,7 +9,7 @@ from chromy.chunk_functions import chunk_file
from chromy.embed import embed
def print_lines(lines: list[str]) -> None:
def print_lines(lines: Sequence[str]) -> None:
for line in lines:
print(line)