From 4ecd6da8d8510861ea991a0b3251f107fcd42444 Mon Sep 17 00:00:00 2001 From: romintomasetti Date: Tue, 24 Mar 2026 21:39:38 +0100 Subject: [PATCH] minor: fix types and use typeguard Signed-off-by: romintomasetti --- .github/workflows/ci.yml | 4 ++-- cmake_file_api/kinds/cache/v2.py | 4 ++-- cmake_file_api/kinds/codemodel/target/v2.py | 4 ++-- cmake_file_api/kinds/codemodel/v2.py | 8 ++++---- cmake_file_api/kinds/common.py | 2 +- cmake_file_api/kinds/configureLog/v1.py | 4 ++-- requirements-dev.txt | 1 + 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc99e25..025d0ba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: python -m pip install -r requirements-dev.txt - name: "Run pytest" run: | - pytest + pytest -vvv --log-cli-level=info --typeguard-packages=cmake_file_api check-typing: runs-on: ubuntu-latest @@ -34,7 +34,7 @@ jobs: with: python-version: "3.10" - run: pip install mypy - - run: mypy --install-types --non-interactive + - run: mypy --install-types --non-interactive --strict pylint: runs-on: ubuntu-latest diff --git a/cmake_file_api/kinds/cache/v2.py b/cmake_file_api/kinds/cache/v2.py index c9b49cd..ac19fd5 100644 --- a/cmake_file_api/kinds/cache/v2.py +++ b/cmake_file_api/kinds/cache/v2.py @@ -2,7 +2,7 @@ from enum import Enum import json from pathlib import Path -from typing import Any +from typing import Any, ClassVar from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -44,7 +44,7 @@ def from_dict(cls, dikt: dict[str, Any]) -> "CacheEntry": return cls(name, value, type, properties) class CacheV2: - KIND = ObjectKind.CACHE + KIND: ClassVar = ObjectKind.CACHE __slots__ = ("version", "entries") diff --git a/cmake_file_api/kinds/codemodel/target/v2.py b/cmake_file_api/kinds/codemodel/target/v2.py index 7a01812..215b30f 100644 --- a/cmake_file_api/kinds/codemodel/target/v2.py +++ b/cmake_file_api/kinds/codemodel/target/v2.py @@ -30,11 +30,11 @@ class ArchiveFragmentRole(enum.Enum): class BacktraceNode: __slots__ = ("file", "line", "command", "parent") - def __init__(self, file: Path, line: Optional[int], command: Optional[str]): + def __init__(self, file: Path, line: Optional[int], command: Optional[str]) -> None: self.file = file self.line = line self.command = command - self.parent = None + self.parent: Optional[BacktraceNode] = None @classmethod def from_dict(cls, dikt: dict[str, Any], commands: list[str], files: list[Path]) -> "BacktraceNode": diff --git a/cmake_file_api/kinds/codemodel/v2.py b/cmake_file_api/kinds/codemodel/v2.py index ca6d8e1..7159b72 100644 --- a/cmake_file_api/kinds/codemodel/v2.py +++ b/cmake_file_api/kinds/codemodel/v2.py @@ -1,6 +1,6 @@ import json from pathlib import Path -from typing import Any, Optional +from typing import Any, ClassVar, Optional from cmake_file_api.kinds.common import CMakeSourceBuildPaths, VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind @@ -18,7 +18,7 @@ def __init__(self, name: str): self.targets: list[CMakeTarget] = [] @classmethod - def from_dict(cls, dikt: dict[str, str]) -> "CMakeProject": + def from_dict(cls, dikt: dict[str, Any]) -> "CMakeProject": name = dikt["name"] return cls(name) @@ -57,7 +57,7 @@ def __init__(self, source: Path, build: Path, minimumCMakeVersion: Optional[str] def from_dict(cls, dikt: dict[str, Any]) -> "CMakeDirectory": source = Path(dikt["source"]) build = Path(dikt["build"]) - minimumCMakeVersion = dikt.get("minimumCMakeVersion", None) + minimumCMakeVersion = dikt['minimumCMakeVersion']['string'] if 'minimumCMakeVersion' in dikt else None hasInstallRule = dikt.get("hasInstallRule", False) return cls(source, build, minimumCMakeVersion, hasInstallRule) @@ -154,7 +154,7 @@ def __repr__(self) -> str: class CodemodelV2: - KIND = ObjectKind.CODEMODEL + KIND: ClassVar = ObjectKind.CODEMODEL __slots__ = ("version", "paths", "configurations") diff --git a/cmake_file_api/kinds/common.py b/cmake_file_api/kinds/common.py index 92efb6f..0a4245b 100644 --- a/cmake_file_api/kinds/common.py +++ b/cmake_file_api/kinds/common.py @@ -10,7 +10,7 @@ def __init__(self, major: int, minor: int): self.minor = minor @classmethod - def from_dict(cls, d: dict[str, str]) -> "VersionMajorMinor": + def from_dict(cls, d: dict[str, int]) -> "VersionMajorMinor": return cls(int(d["major"]), int(d["minor"])) def __repr__(self) -> str: diff --git a/cmake_file_api/kinds/configureLog/v1.py b/cmake_file_api/kinds/configureLog/v1.py index c9c2133..93e8c4a 100644 --- a/cmake_file_api/kinds/configureLog/v1.py +++ b/cmake_file_api/kinds/configureLog/v1.py @@ -1,13 +1,13 @@ import json from pathlib import Path -from typing import Any +from typing import Any, ClassVar from cmake_file_api.kinds.common import VersionMajorMinor from cmake_file_api.kinds.kind import ObjectKind class ConfigureLogV1: - KIND = ObjectKind.CONFIGURELOG + KIND: ClassVar = ObjectKind.CONFIGURELOG __slots__ = ("version", "path", "eventKindNames") diff --git a/requirements-dev.txt b/requirements-dev.txt index 4bfa28c..ed6c7d4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ pytest mypy +typeguard