Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ dev = ["ruff"]

[tool.mypy]
python_version = "3.11"
# Disable for not as we have missing type annotations. See https://github.com/cocoindex-io/cocoindex/issues/539
# strict = true
strict = true
files = "python/cocoindex"
exclude = "python/cocoindex/tests"
2 changes: 1 addition & 1 deletion python/cocoindex/auth_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def add_auth_entry(key: str, value: T) -> AuthEntryReference[T]:
return AuthEntryReference(key)


def ref_auth_entry(key: str) -> AuthEntryReference:
def ref_auth_entry(key: str) -> AuthEntryReference[T]:
"""Reference an auth entry by its key."""
return AuthEntryReference(key)
21 changes: 12 additions & 9 deletions python/cocoindex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
from dotenv import load_dotenv, find_dotenv
from rich.console import Console
from rich.table import Table
from typing import Any

from . import flow, lib, setting, query
from . import flow, lib, setting
from .setup import sync_setup, drop_setup, flow_names_with_setup, apply_setup_changes

# Create ServerSettings lazily upon first call, as environment variables may be loaded from files, etc.
Expand Down Expand Up @@ -126,7 +127,7 @@ def _load_user_app(app_target: str) -> types.ModuleType:
default=None,
show_default=False,
)
def cli(env_file: str | None):
def cli(env_file: str | None) -> None:
"""
CLI for Cocoindex.
"""
Expand All @@ -146,7 +147,7 @@ def cli(env_file: str | None):

@cli.command()
@click.argument("app_target", type=str, required=False)
def ls(app_target: str | None):
def ls(app_target: str | None) -> None:
"""
List all flows.

Expand Down Expand Up @@ -198,7 +199,7 @@ def ls(app_target: str | None):
"--color/--no-color", default=True, help="Enable or disable colored output."
)
@click.option("--verbose", is_flag=True, help="Show verbose output with full details.")
def show(app_flow_specifier: str, color: bool, verbose: bool):
def show(app_flow_specifier: str, color: bool, verbose: bool) -> None:
"""
Show the flow spec and schema.

Expand Down Expand Up @@ -235,7 +236,7 @@ def show(app_flow_specifier: str, color: bool, verbose: bool):

@cli.command()
@click.argument("app_target", type=str)
def setup(app_target: str):
def setup(app_target: str) -> None:
"""
Check and apply backend setup changes for flows, including the internal and target storage
(to export).
Expand Down Expand Up @@ -273,7 +274,7 @@ def setup(app_target: str):
"even if not defined in the current process."
"If used, APP_TARGET and any listed flow names are ignored.",
)
def drop(app_target: str | None, flow_name: tuple[str, ...], drop_all: bool):
def drop(app_target: str | None, flow_name: tuple[str, ...], drop_all: bool) -> None:
"""
Drop the backend setup for flows.

Expand Down Expand Up @@ -354,7 +355,7 @@ def drop(app_target: str | None, flow_name: tuple[str, ...], drop_all: bool):
default=False,
help="Avoid printing anything to the standard output, e.g. statistics.",
)
def update(app_flow_specifier: str, live: bool, quiet: bool):
def update(app_flow_specifier: str, live: bool, quiet: bool) -> Any:
"""
Update the index to reflect the latest data from data sources.

Expand Down Expand Up @@ -389,7 +390,9 @@ def update(app_flow_specifier: str, live: bool, quiet: bool):
default=True,
help="Use already-cached intermediate data if available.",
)
def evaluate(app_flow_specifier: str, output_dir: str | None, cache: bool = True):
def evaluate(
app_flow_specifier: str, output_dir: str | None, cache: bool = True
) -> None:
"""
Evaluate the flow and dump flow outputs to files.

Expand Down Expand Up @@ -472,7 +475,7 @@ def server(
cors_origin: str | None,
cors_cocoindex: bool,
cors_local: int | None,
):
) -> None:
"""
Start a HTTP server providing REST APIs.

Expand Down
10 changes: 5 additions & 5 deletions python/cocoindex/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def encode_engine_value(value: Any) -> Any:
def make_engine_value_decoder(
field_path: list[str],
src_type: dict[str, Any],
dst_annotation,
dst_annotation: Any,
) -> Callable[[Any], Any]:
"""
Make a decoder from an engine value to a Python value.
Expand Down Expand Up @@ -102,7 +102,7 @@ def make_engine_value_decoder(
field_path, engine_fields_schema[1:], elem_type_info.struct_type
)

def decode(value):
def decode(value: Any) -> Any | None:
if value is None:
return None
return {key_decoder(v[0]): value_decoder(v[1:]) for v in value}
Expand All @@ -111,7 +111,7 @@ def decode(value):
field_path, engine_fields_schema, elem_type_info.struct_type
)

def decode(value):
def decode(value: Any) -> Any | None:
if value is None:
return None
return [elem_decoder(v) for v in value]
Expand All @@ -129,7 +129,7 @@ def _make_engine_struct_value_decoder(
field_path: list[str],
src_fields: list[dict[str, Any]],
dst_struct_type: type,
) -> Callable[[list], Any]:
) -> Callable[[list[Any]], Any]:
"""Make a decoder from an engine field values to a Python value."""

src_name_to_idx = {f["name"]: i for i, f in enumerate(src_fields)}
Expand All @@ -156,7 +156,7 @@ def _make_engine_struct_value_decoder(

def make_closure_for_value(
name: str, param: inspect.Parameter
) -> Callable[[list], Any]:
) -> Callable[[list[Any]], Any]:
src_idx = src_name_to_idx.get(name)
if src_idx is not None:
field_path.append(f".{name}")
Expand Down
Loading