clan-cli: Print function name to raise for unsupported types by API.register
This commit is contained in:
@@ -23,12 +23,21 @@ def import_all_modules_from_package(pkg: ModuleType) -> None:
|
||||
importlib.import_module(module_name)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def load_in_all_api_functions() -> None:
|
||||
"""
|
||||
For the global API object, to have all functions available.
|
||||
We have to make sure python loads every wrapped function at least once.
|
||||
This is done by importing all modules from the clan_lib and clan_cli packages.
|
||||
"""
|
||||
import clan_cli
|
||||
import clan_lib
|
||||
|
||||
import_all_modules_from_package(clan_cli)
|
||||
import_all_modules_from_package(clan_lib)
|
||||
import_all_modules_from_package(clan_cli)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
load_in_all_api_functions()
|
||||
|
||||
from clan_lib.api import API
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ from typing import (
|
||||
get_type_hints,
|
||||
)
|
||||
|
||||
from clan_lib.api.util import JSchemaTypeError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from .serde import dataclass_to_dict, from_dict, sanitize_string
|
||||
@@ -217,12 +219,16 @@ API.register(open_file)
|
||||
for name, func in self._registry.items():
|
||||
hints = get_type_hints(func)
|
||||
|
||||
serialized_hints = {
|
||||
key: type_to_dict(
|
||||
value, scope=name + " argument" if key != "return" else "return"
|
||||
)
|
||||
for key, value in hints.items()
|
||||
}
|
||||
try:
|
||||
serialized_hints = {
|
||||
key: type_to_dict(
|
||||
value, scope=name + " argument" if key != "return" else "return"
|
||||
)
|
||||
for key, value in hints.items()
|
||||
}
|
||||
except JSchemaTypeError as e:
|
||||
msg = f"Error serializing type hints for function '{name}': {e}"
|
||||
raise JSchemaTypeError(msg) from e
|
||||
|
||||
return_type = serialized_hints.pop("return")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user