From e0f56e40338efdd4cc7619890e3c74cf792bdf71 Mon Sep 17 00:00:00 2001 From: codeasier Date: Wed, 22 Apr 2026 00:14:05 +0800 Subject: [PATCH 1/2] ci: add basedpyright check to test workflow Run basedpyright in CI with the active Python interpreter and add the minimal project config needed to keep local and CI checks aligned. --- .github/workflows/test.yml | 3 +++ pyproject.toml | 8 ++++++++ src/pt_snap_cli/__init__.py | 2 +- src/pt_snap_cli/cli.py | 25 ++++++++++++++++--------- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46647d6..53549a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,6 +30,9 @@ jobs: - name: Black format check run: black --check . + - name: basedPyright check + run: python -m basedpyright --pythonpath "$(python -c 'import sys; print(sys.executable)')" + test: name: Test (Python ${{ matrix.python-version }}) runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index cd9794c..8ea175b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ dev = [ "black>=23.0.0", "ruff>=0.0.280", "build>=1.0.0", + "basedpyright>=1.39.3", ] rag = [ "chromadb>=0.4.0", @@ -78,6 +79,13 @@ python_files = ["test_*.py"] python_functions = ["test_*"] addopts = "-v --tb=short" +[tool.basedpyright] +pythonVersion = "3.13" +include = [ + "src/pt_snap_cli/cli.py", + "src/pt_snap_cli/__init__.py", +] + [tool.coverage.run] source = ["pt_snap_cli"] branch = true diff --git a/src/pt_snap_cli/__init__.py b/src/pt_snap_cli/__init__.py index 131b93b..2ed9b56 100644 --- a/src/pt_snap_cli/__init__.py +++ b/src/pt_snap_cli/__init__.py @@ -2,4 +2,4 @@ from pt_snap_cli.version import __version__ -__all__ = ["__version__", "query"] +__all__ = ["__version__"] diff --git a/src/pt_snap_cli/cli.py b/src/pt_snap_cli/cli.py index 908501b..9812b82 100644 --- a/src/pt_snap_cli/cli.py +++ b/src/pt_snap_cli/cli.py @@ -4,8 +4,9 @@ import json import shlex +from collections.abc import Mapping from pathlib import Path -from typing import Annotated +from typing import Annotated, NoReturn, cast import typer @@ -51,7 +52,7 @@ def version_callback(value: bool) -> None: @app.callback() def main( - version: Annotated[ + _: Annotated[ bool | None, typer.Option("--version", "-v", help="Show version and exit", callback=version_callback), ] = None, @@ -117,15 +118,18 @@ def focus_database( raise typer.Exit() try: + focus_db_path = db_path + if focus_db_path is None: + raise AssertionError("db_path must be provided when setting focus") if session: - state = focus_service.validate_session_db(db_path) + state = focus_service.validate_session_db(focus_db_path) typer.echo(f"export {ENV_DB_PATH}={shlex.quote(str(state.db_path))}") return if global_focus: - state = focus_service.set_global_focus(db_path, device) + state = focus_service.set_global_focus(focus_db_path, device) typer.secho(f"Using global database: {state.db_path}", fg=typer.colors.GREEN) else: - state = focus_service.set_project_focus(db_path, device) + state = focus_service.set_project_focus(focus_db_path, device) typer.secho(f"Using project database: {state.db_path}", fg=typer.colors.GREEN) if state.focus_file: typer.echo(f"Focus file: {state.focus_file}") @@ -207,7 +211,7 @@ def query_database( } if category is not None: filter_cats = [category] - query_service.list_templates(category) + _ = query_service.list_templates(category) else: filter_cats = categories any_found = False @@ -289,7 +293,10 @@ def query_database( _error("--template-use is required when not using --list or --template-info") try: - query_params = json.loads(params) if params else {} + loaded_params = json.loads(params) if params else {} # pyright: ignore[reportUnknownVariableType] + if not isinstance(loaded_params, dict): + raise ValueError("Query parameters must be a JSON object.") + query_params = cast(dict[str, object], loaded_params) result = query_service.execute_query( template=template_use, params=query_params, @@ -369,11 +376,11 @@ def show_config( typer.echo("No configuration set.") else: typer.echo("Current configuration:") - for key, value in current_config.items(): + for key, value in cast(Mapping[str, object], current_config).items(): typer.echo(f" {key}: {value}") -def _error(message: str) -> None: +def _error(message: str) -> NoReturn: typer.secho(f"Error: {message}", fg=typer.colors.RED) raise typer.Exit(1) from None From 7fd3bc6915af8f2808a6a048edea30ba2bcbc406 Mon Sep 17 00:00:00 2001 From: codeasier Date: Wed, 22 Apr 2026 09:25:22 +0800 Subject: [PATCH 2/2] style: fix black formatting in cli.py --- src/pt_snap_cli/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pt_snap_cli/cli.py b/src/pt_snap_cli/cli.py index 9812b82..1d4f8f0 100644 --- a/src/pt_snap_cli/cli.py +++ b/src/pt_snap_cli/cli.py @@ -293,7 +293,9 @@ def query_database( _error("--template-use is required when not using --list or --template-info") try: - loaded_params = json.loads(params) if params else {} # pyright: ignore[reportUnknownVariableType] + loaded_params = ( # pyright: ignore[reportUnknownVariableType] + json.loads(params) if params else {} + ) if not isinstance(loaded_params, dict): raise ValueError("Query parameters must be a JSON object.") query_params = cast(dict[str, object], loaded_params)