api: fix typing issues

This commit is contained in:
Johannes Kirschbauer
2024-05-21 15:57:27 +02:00
parent 21104a0465
commit c1e7e25641
8 changed files with 19 additions and 18 deletions

View File

@@ -1,9 +1,10 @@
from collections.abc import Callable
from typing import Any
class _MethodRegistry:
def __init__(self):
self._registry = {}
def __init__(self) -> None:
self._registry: dict[str, Callable] = {}
def register(self, fn: Callable) -> Callable:
self._registry[fn.__name__] = fn
@@ -13,9 +14,10 @@ class _MethodRegistry:
# Import only when needed
import json
from typing import get_type_hints
from clan_cli.api.util import type_to_dict
api_schema = {
api_schema: dict[str, Any] = {
"$comment": "An object containing API methods. ",
"type": "object",
"additionalProperties": False,

View File

@@ -1,7 +1,7 @@
import dataclasses
from types import NoneType, UnionType
from typing import Any, Callable, Union, get_type_hints
import pathlib
from types import NoneType, UnionType
from typing import Any, Union
def type_to_dict(t: Any, scope: str = "") -> dict:
@@ -46,7 +46,7 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
"type": "object",
}
raise BaseException(f"Error api type not yet supported {str(t)}")
raise BaseException(f"Error api type not yet supported {t!s}")
elif isinstance(t, type):
if t is str:
@@ -74,6 +74,6 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
if t is NoneType:
return {"type": "null"}
raise BaseException(f"Error primitive type not supported {str(t)}")
raise BaseException(f"Error primitive type not supported {t!s}")
else:
raise BaseException(f"Error type not supported {str(t)}")
raise BaseException(f"Error type not supported {t!s}")

View File

@@ -3,9 +3,10 @@ import json
import logging
from pathlib import Path
from clan_cli.api import API
from ..cmd import run
from ..nix import nix_config, nix_eval
from clan_cli.api import API
log = logging.getLogger(__name__)