Skip to content

Commit 953b8c7

Browse files
committed
fix types
1 parent 14e0264 commit 953b8c7

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

Diff for: idom/server/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def stop(self) -> None:
8989
self.loop.call_soon_threadsafe(self._stop)
9090

9191
@abc.abstractmethod
92-
def _stop(self):
92+
def _stop(self) -> None:
9393
raise NotImplementedError()
9494

9595
@abc.abstractmethod

Diff for: idom/server/utils.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@
1111
_S = TypeVar("_S", bound=AbstractRenderServer[Any, Any])
1212

1313

14-
def _find_default_server_type() -> Optional[Type[AbstractRenderServer[Any, Any]]]:
14+
def _find_default_server_type() -> Optional[Type[_S]]:
1515
for name in ["sanic.PerClientStateServer"]:
1616
module_name, server_name = name.split(".")
1717
try:
1818
module = import_module(f"idom.server.{module_name}")
1919
except ImportError: # pragma: no cover
2020
pass
2121
else:
22-
return getattr(module, server_name)
22+
return cast(Type[_S], getattr(module, server_name))
2323
else: # pragma: no cover
2424
return None
2525

2626

2727
def run(
2828
element: ElementConstructor,
2929
server_type: Optional[Type[_S]] = _find_default_server_type(),
30-
host: Optional[str] = "127.0.0.1",
30+
host: str = "127.0.0.1",
3131
port: Optional[int] = None,
3232
server_options: Optional[Any] = None,
3333
run_options: Optional[Dict[str, Any]] = None,
@@ -68,7 +68,7 @@ def run(
6868

6969
def multiview_server(
7070
server_type: Type[_S],
71-
host: Optional[str] = "127.0.0.1",
71+
host: str = "127.0.0.1",
7272
port: Optional[int] = None,
7373
server_options: Optional[Any] = None,
7474
run_options: Optional[Dict[str, Any]] = None,
@@ -110,7 +110,7 @@ def multiview_server(
110110

111111
def hotswap_server(
112112
server_type: Type[_S],
113-
host: Optional[str] = "127.0.0.1",
113+
host: str = "127.0.0.1",
114114
port: Optional[int] = None,
115115
server_options: Optional[Any] = None,
116116
run_options: Optional[Dict[str, Any]] = None,

Diff for: idom/widgets/utils.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
from typing import Any, Callable, Tuple, Dict, Set, cast
2-
3-
from typing_extensions import Protocol
1+
from typing import TypeVar, Any, Callable, Tuple, Dict, Set
42

53
from idom.core import hooks
64
from idom.core.element import ElementConstructor, element
75
from idom.utils import Ref
86

97

10-
class MountFunc(Protocol):
11-
"""Function for mounting views"""
12-
13-
def __call__(
14-
self, constructor: ElementConstructor, *args: Any, **kwargs: Any
15-
) -> Any:
16-
...
8+
MountFunc = Callable[[ElementConstructor], None]
179

1810

1911
def hotswap(shared: bool = False) -> Tuple[MountFunc, ElementConstructor]:
@@ -82,16 +74,22 @@ def swap(constructor: Callable[[], Any]) -> None:
8274
def HotSwap() -> Any:
8375
return constructor_ref.current()
8476

85-
def swap(constructor: ElementConstructor) -> None:
77+
def swap(constructor: Callable[[], Any]) -> None:
8678
constructor_ref.current = constructor
8779
return None
8880

89-
return cast(MountFunc, swap), HotSwap
81+
return swap, HotSwap
82+
83+
84+
_Func = Callable[..., Any]
85+
_FuncVar = TypeVar("_FuncVar", bound=_Func)
9086

9187

92-
def _use_callable(initial_func):
93-
func, _set_func = hooks.use_state(lambda: initial_func)
94-
return func, lambda new: _set_func(lambda old: new)
88+
def _use_callable(initial_func: _FuncVar) -> Tuple[_FuncVar, Callable[[_Func], None]]:
89+
state: Tuple[_FuncVar, Callable[[_Func], None]] = hooks.use_state(
90+
lambda: initial_func
91+
)
92+
return state[0], lambda new: state[1](lambda old: new)
9593

9694

9795
def multiview() -> Tuple["MultiViewMount", ElementConstructor]:
@@ -148,7 +146,7 @@ def __init__(self, views: Dict[str, ElementConstructor]):
148146
def remove(self, view_id: str) -> None:
149147
del self._views[view_id]
150148

151-
def __getitem__(self, view_id: str) -> MountFunc:
149+
def __getitem__(self, view_id: str) -> Callable[[ElementConstructor], str]:
152150
def mount(constructor: ElementConstructor) -> str:
153151
self._views[view_id] = constructor
154152
return view_id
@@ -161,5 +159,5 @@ def __call__(self, constructor: ElementConstructor) -> str:
161159
self._views[view_id] = constructor
162160
return view_id
163161

164-
def __repr__(self):
162+
def __repr__(self) -> str:
165163
return f"{type(self).__name__}({self._views})"

0 commit comments

Comments
 (0)