modernize type hints
This commit is contained in:
@@ -1 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""Chromy package."""
|
||||
|
||||
@@ -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
@@ -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 [
|
||||
{
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""Command handlers package for the Chroma CLI."""
|
||||
|
||||
+4
-2
@@ -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)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# 7. Modernize Type Hints and Add Missing Future Imports
|
||||
# 7. Modernize Type Hints and Add Missing Future Imports [DONE]
|
||||
|
||||
## Summary
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""Tests for the Chromy CLI."""
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user