Skip to content

Commit eed5276

Browse files
sigma67madebr
authored andcommitted
fix remaining issues
1 parent 5c633c2 commit eed5276

File tree

8 files changed

+29
-18
lines changed

8 files changed

+29
-18
lines changed

cmake_file_api/kinds/api.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
from pathlib import Path
2+
from typing import Protocol
3+
from typing_extensions import Self
4+
15
from .kind import ObjectKind
26
from .cache.api import CACHE_API
37
from .cmakeFiles.api import CMAKEFILES_API
@@ -6,7 +10,14 @@
610
from .toolchains.api import TOOLCHAINS_API
711

812

9-
OBJECT_KINDS_API = {
13+
class CMakeApiType(Protocol):
14+
KIND: ObjectKind
15+
16+
@classmethod
17+
def from_path(cls, path: Path, reply_path: Path) -> Self:
18+
...
19+
20+
OBJECT_KINDS_API: dict[ObjectKind, dict[int, CMakeApiType]] = {
1021
ObjectKind.CACHE: CACHE_API,
1122
ObjectKind.CMAKEFILES: CMAKEFILES_API,
1223
ObjectKind.CONFIGURELOG: CONFIGURELOG_API,

cmake_file_api/kinds/cache/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .v2 import CacheV2
2+
from ..api import CMakeApiType
23

3-
4-
CACHE_API = {
4+
CACHE_API: dict[int, CMakeApiType] = {
55
2: CacheV2,
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .v1 import CMakeFilesV1
2+
from ..api import CMakeApiType
23

3-
4-
CMAKEFILES_API = {
4+
CMAKEFILES_API: dict[int, CMakeApiType] = {
55
1: CMakeFilesV1,
66
}

cmake_file_api/kinds/codemodel/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .v2 import CodemodelV2
2+
from ..api import CMakeApiType
23

3-
4-
CODEMODEL_API = {
4+
CODEMODEL_API: dict[int, CMakeApiType] = {
55
2: CodemodelV2,
66
}

cmake_file_api/kinds/codemodel/target/v2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ def __repr__(self) -> str:
284284
class TargetCompileGroupPCH:
285285
__slots__ = ("header", "backtrace")
286286

287-
def __init__(self, header: Path, backtrace: BacktraceNode):
287+
def __init__(self, header: Path, backtrace: Optional[BacktraceNode]):
288288
self.header = header
289289
self.backtrace = backtrace
290290

@@ -307,7 +307,7 @@ def __repr__(self) -> str:
307307
class TargetCompileGroupDefine:
308308
__slots__ = ("define", "backtrace")
309309

310-
def __init__(self, define: str, backtrace: BacktraceNode):
310+
def __init__(self, define: str, backtrace: Optional[BacktraceNode]):
311311
self.define = define
312312
self.backtrace = backtrace
313313

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .v1 import ConfigureLogV1
2+
from ..api import CMakeApiType
23

3-
4-
CONFIGURELOG_API = {
4+
CONFIGURELOG_API: dict[int, CMakeApiType] = {
55
1: ConfigureLogV1,
66
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from .v1 import ToolchainsV1
2+
from ..api import CMakeApiType
23

3-
4-
TOOLCHAINS_API = {
4+
TOOLCHAINS_API: dict[int, CMakeApiType] = {
55
1: ToolchainsV1,
66
}

cmake_file_api/reply/v1/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from pathlib import Path
2-
from typing import Optional
2+
from typing import Any, Optional
33

44
from cmake_file_api.errors import CMakeException
5-
from cmake_file_api.kinds.api import OBJECT_KINDS_API
5+
from cmake_file_api.kinds.api import CMakeApiType, OBJECT_KINDS_API
66
from cmake_file_api.kinds.cmakeFiles.v1 import CMakeFilesV1
77
from cmake_file_api.reply.index.api import INDEX_API
88
from cmake_file_api.kinds.kind import ObjectKind
@@ -68,14 +68,14 @@ def index(self) -> CMakeReplyFileV1:
6868
reply_path = self._create_reply_path()
6969
return self._index(reply_path)
7070

71-
def inspect(self, kind: ObjectKind, kind_version: int) -> Optional[CMakeFilesV1]:
71+
def inspect(self, kind: ObjectKind, kind_version: int) -> Optional[CMakeApiType]:
7272
reply_path = self._create_reply_path()
7373
index = self._index(reply_path)
7474

7575
data_path = index.reply.stateless.get((kind, kind_version), None)
7676
if data_path is None:
7777
return None
78-
api = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None)
78+
api: Optional[CMakeApiType] = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None)
7979
if api is None:
8080
return None
8181
return api.from_path(reply_path / str(data_path.jsonFile), reply_path)
@@ -84,7 +84,7 @@ def inspect_all(self) -> dict[ObjectKind, dict[int, object]]:
8484
reply_path = self._create_reply_path()
8585
index = self._index(reply_path)
8686

87-
result = {}
87+
result: dict[ObjectKind, dict[int, Any]] = {}
8888
for (kind, kind_version), reply_file_ref in index.reply.stateless.items():
8989
api = OBJECT_KINDS_API.get(kind, {}).get(kind_version, None)
9090
if api is None:

0 commit comments

Comments
 (0)