From 2dfaa68466c2d265e93d07540408c22d2fc9fc52 Mon Sep 17 00:00:00 2001 From: Matteo Rosati Date: Wed, 22 Apr 2026 17:19:14 +0200 Subject: [PATCH] modernize type hints --- chromy/__init__.py | 2 ++ chromy/chroma_functions.py | 10 +++++++--- chromy/embed.py | 5 +++-- chromy/handlers/__init__.py | 2 ++ chromy/utilities.py | 6 ++++-- ...type-hints.md => 07-_done_-modernize-type-hints.md} | 2 +- tests/__init__.py | 2 ++ tests/test_cli_command_inputs.py | 3 ++- 8 files changed, 23 insertions(+), 9 deletions(-) rename plans/{07-modernize-type-hints.md => 07-_done_-modernize-type-hints.md} (94%) diff --git a/chromy/__init__.py b/chromy/__init__.py index fab4035..daab70a 100644 --- a/chromy/__init__.py +++ b/chromy/__init__.py @@ -1 +1,3 @@ +from __future__ import annotations + """Chromy package.""" diff --git a/chromy/chroma_functions.py b/chromy/chroma_functions.py index 82816bf..569447f 100644 --- a/chromy/chroma_functions.py +++ b/chromy/chroma_functions.py @@ -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)) diff --git a/chromy/embed.py b/chromy/embed.py index 12bfeba..d2dcfe6 100644 --- a/chromy/embed.py +++ b/chromy/embed.py @@ -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 [ { diff --git a/chromy/handlers/__init__.py b/chromy/handlers/__init__.py index 581cc81..06adc33 100644 --- a/chromy/handlers/__init__.py +++ b/chromy/handlers/__init__.py @@ -1 +1,3 @@ +from __future__ import annotations + """Command handlers package for the Chroma CLI.""" diff --git a/chromy/utilities.py b/chromy/utilities.py index 94f1402..9b39b15 100644 --- a/chromy/utilities.py +++ b/chromy/utilities.py @@ -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) diff --git a/plans/07-modernize-type-hints.md b/plans/07-_done_-modernize-type-hints.md similarity index 94% rename from plans/07-modernize-type-hints.md rename to plans/07-_done_-modernize-type-hints.md index 767b75f..876a931 100644 --- a/plans/07-modernize-type-hints.md +++ b/plans/07-_done_-modernize-type-hints.md @@ -1,4 +1,4 @@ -# 7. Modernize Type Hints and Add Missing Future Imports +# 7. Modernize Type Hints and Add Missing Future Imports [DONE] ## Summary diff --git a/tests/__init__.py b/tests/__init__.py index 38d2e1c..729d579 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,3 @@ +from __future__ import annotations + """Tests for the Chromy CLI.""" diff --git a/tests/test_cli_command_inputs.py b/tests/test_cli_command_inputs.py index 392551d..b1f4dca 100644 --- a/tests/test_cli_command_inputs.py +++ b/tests/test_cli_command_inputs.py @@ -3,6 +3,7 @@ from __future__ import annotations import io import unittest from argparse import Namespace +from collections.abc import Sequence from contextlib import redirect_stdout from chromy.cli_app import build_command_input, execute_command @@ -89,7 +90,7 @@ class BuildCommandInputTests(unittest.TestCase): 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))