From 748b87f8f6ba98b293006c69ba3376983f5eb96a Mon Sep 17 00:00:00 2001 From: Anish Athalye Date: Tue, 28 Jan 2025 11:01:45 -0800 Subject: [PATCH] Switch to strict static type checking --- pyproject.toml | 4 ++-- src/cleanlab_codex/utils/smolagents.py | 2 +- tests/internal/test_utils.py | 6 +++--- tests/test_codex.py | 18 +++++++++--------- tests/test_codex_tool.py | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b036139..b987ac1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,7 @@ extra-dependencies = [ "smolagents", ] [tool.hatch.envs.types.scripts] -check = "mypy --install-types --non-interactive {args:src/cleanlab_codex tests}" +check = "mypy --strict --install-types --non-interactive {args:src/cleanlab_codex tests}" [tool.hatch.metadata] allow-direct-references = true @@ -68,7 +68,7 @@ cov-combine = "coverage combine" cov-report = "coverage report {env:COVERAGE_FAIL_UNDER}" [tool.coverage.run] -source_pkgs = ["cleanlab_codex", "tests"] +source_pkgs = ["cleanlab_codex", "tests"] branch = true parallel = true omit = [ diff --git a/src/cleanlab_codex/utils/smolagents.py b/src/cleanlab_codex/utils/smolagents.py index a7e0bb8..f78aa47 100644 --- a/src/cleanlab_codex/utils/smolagents.py +++ b/src/cleanlab_codex/utils/smolagents.py @@ -3,7 +3,7 @@ from smolagents import Tool # type: ignore -class CodexTool(Tool): +class CodexTool(Tool): # type: ignore[misc] def __init__( self, query: Callable[[str], Optional[str]], diff --git a/tests/internal/test_utils.py b/tests/internal/test_utils.py index 8448796..9c80895 100644 --- a/tests/internal/test_utils.py +++ b/tests/internal/test_utils.py @@ -6,19 +6,19 @@ DUMMY_API_KEY = "GP0FzPfA7wYy5L64luII2YaRT2JoSXkae7WEo7dH6Bw" -def test_is_access_key(): +def test_is_access_key() -> None: assert is_access_key(DUMMY_ACCESS_KEY) assert not is_access_key(DUMMY_API_KEY) -def test_init_codex_client_access_key(): +def test_init_codex_client_access_key() -> None: with patch("cleanlab_codex.internal.utils._Codex", autospec=True) as mock_codex: client = init_codex_client(DUMMY_ACCESS_KEY) mock_codex.assert_called_once_with(access_key=DUMMY_ACCESS_KEY) assert client is not None -def test_init_codex_client_api_key(): +def test_init_codex_client_api_key() -> None: with patch("cleanlab_codex.internal.utils._Codex", autospec=True) as mock_codex: client = init_codex_client(DUMMY_API_KEY) mock_codex.assert_called_once_with(api_key=DUMMY_API_KEY) diff --git a/tests/test_codex.py b/tests/test_codex.py index 9ec6c44..fa6ff12 100644 --- a/tests/test_codex.py +++ b/tests/test_codex.py @@ -22,7 +22,7 @@ DEFAULT_PROJECT_CONFIG = ProjectConfig() -def test_list_organizations(mock_client: MagicMock): +def test_list_organizations(mock_client: MagicMock) -> None: mock_client.users.myself.organizations.list.return_value = UserOrganizationsSchema( organizations=[ Organization( @@ -40,7 +40,7 @@ def test_list_organizations(mock_client: MagicMock): assert organizations[0].user_id == FAKE_USER_ID -def test_create_project(mock_client: MagicMock): +def test_create_project(mock_client: MagicMock) -> None: mock_client.projects.create.return_value = ProjectReturnSchema( id=FAKE_PROJECT_ID, config=Config(), @@ -62,7 +62,7 @@ def test_create_project(mock_client: MagicMock): assert project_id == FAKE_PROJECT_ID -def test_add_entries(mock_client: MagicMock): +def test_add_entries(mock_client: MagicMock) -> None: answered_entry_create = EntryCreate( question="What is the capital of France?", answer="Paris", @@ -82,7 +82,7 @@ def test_add_entries(mock_client: MagicMock): assert call.kwargs["answer"] == entry.get("answer") -def test_create_project_access_key(mock_client: MagicMock): +def test_create_project_access_key(mock_client: MagicMock) -> None: codex = Codex("") access_key_name = "Test Access Key" access_key_description = "Test Access Key Description" @@ -94,7 +94,7 @@ def test_create_project_access_key(mock_client: MagicMock): ) -def test_query_no_project_id(mock_client: MagicMock): +def test_query_no_project_id(mock_client: MagicMock) -> None: mock_client.access_key = None codex = Codex("") @@ -102,7 +102,7 @@ def test_query_no_project_id(mock_client: MagicMock): codex.query("What is the capital of France?") -def test_query_read_only(mock_client: MagicMock): +def test_query_read_only(mock_client: MagicMock) -> None: mock_client.access_key = None mock_client.projects.entries.query.return_value = None @@ -115,7 +115,7 @@ def test_query_read_only(mock_client: MagicMock): assert res == (None, None) -def test_query_question_found_fallback_answer(mock_client: MagicMock): +def test_query_question_found_fallback_answer(mock_client: MagicMock) -> None: unanswered_entry = Entry( id=str(uuid.uuid4()), created_at=datetime.now(), @@ -128,7 +128,7 @@ def test_query_question_found_fallback_answer(mock_client: MagicMock): assert res == (None, unanswered_entry) -def test_query_question_not_found_fallback_answer(mock_client: MagicMock): +def test_query_question_not_found_fallback_answer(mock_client: MagicMock) -> None: mock_client.projects.entries.query.return_value = None mock_client.projects.entries.add_question.return_value = None @@ -137,7 +137,7 @@ def test_query_question_not_found_fallback_answer(mock_client: MagicMock): assert res == ("Paris", None) -def test_query_answer_found(mock_client: MagicMock): +def test_query_answer_found(mock_client: MagicMock) -> None: answered_entry = Entry( id=str(uuid.uuid4()), created_at=datetime.now(), diff --git a/tests/test_codex_tool.py b/tests/test_codex_tool.py index 89a457e..1d72d83 100644 --- a/tests/test_codex_tool.py +++ b/tests/test_codex_tool.py @@ -7,7 +7,7 @@ from cleanlab_codex.codex_tool import CodexTool -def test_to_openai_tool(mock_client: MagicMock): # noqa: ARG001 +def test_to_openai_tool(mock_client: MagicMock) -> None: # noqa: ARG001 tool = CodexTool.from_access_key("") openai_tool = tool.to_openai_tool() assert openai_tool.get("type") == "function" @@ -16,7 +16,7 @@ def test_to_openai_tool(mock_client: MagicMock): # noqa: ARG001 assert openai_tool.get("function", {}).get("parameters", {}).get("type") == "object" -def test_to_llamaindex_tool(mock_client: MagicMock): # noqa: ARG001 +def test_to_llamaindex_tool(mock_client: MagicMock) -> None: # noqa: ARG001 tool = CodexTool.from_access_key("") llama_index_tool = tool.to_llamaindex_tool() assert isinstance(llama_index_tool, FunctionTool) @@ -26,7 +26,7 @@ def test_to_llamaindex_tool(mock_client: MagicMock): # noqa: ARG001 @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires python3.10 or higher") -def test_to_smolagents_tool(mock_client: MagicMock): # noqa: ARG001 +def test_to_smolagents_tool(mock_client: MagicMock) -> None: # noqa: ARG001 from smolagents import Tool # type: ignore tool = CodexTool.from_access_key("")