diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 04d3694..239a2a4 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -26,6 +26,8 @@ jobs: run: make check-format - name: Run linter run: make lint + - name: Type check + run: make typecheck - name: Security audit run: make audit @@ -49,5 +51,7 @@ jobs: run: make check-format - name: Run linter run: make lint + - name: Type check + run: make typecheck - name: Security audit run: make audit diff --git a/CHANGELOG.md b/CHANGELOG.md index d0341fc..ec13370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to - CI: use Makefile targets in Windows job and add sequential per-commit testing triggered by the ci:per-commit label ([3967e42], [#66]) - Remove duplicated lint-shell target in Makefile ([a652654], [#67]) +- Add mypy type checking to CI workflow ([6b9a3db], [#42]) - Migrate from Poetry to uv ([14bc55e], [#65]) ## [0.1.10] - 2024-12-XX @@ -64,6 +65,7 @@ and this project adheres to [0.1.9]: https://github.com/LeakIX/LeakIXClient-Python/releases/tag/v0.1.9 +[6b9a3db]: https://github.com/LeakIX/LeakIXClient-Python/commit/6b9a3db [d111628]: https://github.com/LeakIX/LeakIXClient-Python/commit/d111628 [df916e5]: https://github.com/LeakIX/LeakIXClient-Python/commit/df916e5 [14bc55e]: https://github.com/LeakIX/LeakIXClient-Python/commit/14bc55e @@ -82,4 +84,5 @@ and this project adheres to [#66]: https://github.com/LeakIX/LeakIXClient-Python/pull/66 [#65]: https://github.com/LeakIX/LeakIXClient-Python/issues/65 [#67]: https://github.com/LeakIX/LeakIXClient-Python/issues/67 +[#42]: https://github.com/LeakIX/LeakIXClient-Python/issues/42 [#68]: https://github.com/LeakIX/LeakIXClient-Python/pull/68 diff --git a/leakix/client.py b/leakix/client.py index 29353f7..067d0e2 100644 --- a/leakix/client.py +++ b/leakix/client.py @@ -2,7 +2,7 @@ import json from enum import Enum from importlib.metadata import version -from typing import Any +from typing import Any, cast import requests from l9format import l9format @@ -99,9 +99,7 @@ def get( if queries is None or len(queries) == 0: serialized_query = EmptyQuery().serialize() else: - serialized_query = [q.serialize() for q in queries] - serialized_query = " ".join(serialized_query) - serialized_query = f"{serialized_query}" + serialized_query = " ".join(q.serialize() for q in queries) url = f"{self.base_url}/search" r = self.__get( url=url, @@ -149,7 +147,7 @@ def get_host(self, ipv4: str) -> AbstractResponse: r = self.__get(url, params=None) if r.is_success(): response_json = r.json() - formatted_result = HostResult.from_dict(response_json) + formatted_result = cast(HostResult, HostResult.from_dict(response_json)) response_json = { "services": formatted_result.Services, "leaks": formatted_result.Leaks, @@ -190,9 +188,7 @@ def bulk_export(self, queries: list[Query] | None = None) -> AbstractResponse: if queries is None or len(queries) == 0: serialized_query = EmptyQuery().serialize() else: - serialized_query = [q.serialize() for q in queries] - serialized_query = " ".join(serialized_query) - serialized_query = f"{serialized_query}" + serialized_query = " ".join(q.serialize() for q in queries) params = {"q": serialized_query} r = requests.get(url, params=params, headers=self.headers, stream=True) if r.status_code == 200: @@ -228,9 +224,7 @@ def bulk_service(self, queries: list[Query] | None = None) -> AbstractResponse: if queries is None or len(queries) == 0: serialized_query = EmptyQuery().serialize() else: - serialized_query = [q.serialize() for q in queries] - serialized_query = " ".join(serialized_query) - serialized_query = f"{serialized_query}" + serialized_query = " ".join(q.serialize() for q in queries) params = {"q": serialized_query} r = requests.get(url, params=params, headers=self.headers, stream=True) if r.status_code == 200: diff --git a/pyproject.toml b/pyproject.toml index a769f1e..648c835 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dev = [ "pytest", "pytest-cov", "mypy", + "types-requests", "requests-mock", "ruff", "pip-audit",