clan-app: Fix mypy lints and add GenericFnRuntime

This commit is contained in:
Qubasa
2024-07-15 19:48:20 +02:00
parent 660ac92c29
commit 77dc90d3b4
8 changed files with 83 additions and 85 deletions

View File

@@ -50,10 +50,22 @@ def update_wrapper_signature(wrapper: Callable, wrapped: Callable) -> None:
wrapper.__signature__ = new_sig # type: ignore
class _MethodRegistry:
class MethodRegistry:
def __init__(self) -> None:
self._orig_annotations: dict[str, Callable[[Any], Any]] = {}
self._registry: dict[str, Callable[[Any], Any]] = {}
self._orig_annotations: dict[str, dict[str, Any]] = {}
self._registry: dict[str, Callable[..., Any]] = {}
@property
def annotations(self) -> dict[str, dict[str, Any]]:
return self._orig_annotations
@property
def functions(self) -> dict[str, Callable[..., Any]]:
return self._registry
def reset(self) -> None:
self._orig_annotations.clear()
self._registry.clear()
def register_abstract(self, fn: Callable[..., T]) -> Callable[..., T]:
@wraps(fn)
@@ -84,7 +96,6 @@ API.register(open_file)
return fn
def register(self, fn: Callable[..., T]) -> Callable[..., T]:
if fn.__name__ in self._registry:
raise ValueError(f"Function {fn.__name__} already registered")
if fn.__name__ in self._orig_annotations:
@@ -189,4 +200,4 @@ API.register(open_file)
return None
API = _MethodRegistry()
API = MethodRegistry()