Skip to content

Commit f390bf7

Browse files
committed
fix for latest mypy
1 parent 356384f commit f390bf7

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

src/idom/core/hooks.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,31 @@
4646
_StateType = TypeVar("_StateType")
4747

4848

49+
@overload
50+
def use_state(
51+
initial_value: Callable[[], _StateType],
52+
) -> Tuple[
53+
_StateType,
54+
Callable[[_StateType | Callable[[_StateType], _StateType]], None],
55+
]:
56+
...
57+
58+
59+
@overload
60+
def use_state(
61+
initial_value: _StateType,
62+
) -> Tuple[
63+
_StateType,
64+
Callable[[_StateType | Callable[[_StateType], _StateType]], None],
65+
]:
66+
...
67+
68+
4969
def use_state(
50-
initial_value: Union[_StateType, Callable[[], _StateType]],
70+
initial_value: _StateType | Callable[[], _StateType],
5171
) -> Tuple[
52-
_StateType, Callable[[Union[_StateType, Callable[[_StateType], _StateType]]], None]
72+
_StateType,
73+
Callable[[_StateType | Callable[[_StateType], _StateType]], None],
5374
]:
5475
"""See the full :ref:`Use State` docs for details
5576

src/idom/server/prefab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def run(
5959
logger.info(f"Using {type(server).__name__}")
6060

6161
run_server = server.run if not daemon else server.run_in_thread
62-
run_server(host, port, **(run_kwargs or {})) # type: ignore
62+
run_server(host, port, **(run_kwargs or {}))
6363
server.wait_until_started()
6464

6565
return server

src/idom/server/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
_FuncParams = ParamSpec("_FuncParams")
2929

3030

31-
def threaded(function: Callable[_FuncParams, None]) -> Callable[_FuncParams, Thread]: # type: ignore
31+
def threaded(function: Callable[_FuncParams, None]) -> Callable[_FuncParams, Thread]:
3232
@wraps(function)
3333
def wrapper(*args: Any, **kwargs: Any) -> Thread:
3434
def target() -> None:

src/idom/widgets.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from base64 import b64encode
4-
from typing import Any, Callable, Dict, Optional, Set, Tuple, TypeVar, Union
4+
from typing import Any, Callable, Dict, Optional, Set, Tuple, Union
55

66
import idom
77

@@ -136,13 +136,10 @@ def swap(constructor: Callable[[], Any]) -> None:
136136

137137

138138
_Func = Callable[..., Any]
139-
_FuncVar = TypeVar("_FuncVar", bound=_Func)
140139

141140

142-
def _use_callable(initial_func: _FuncVar) -> Tuple[_FuncVar, Callable[[_Func], None]]:
143-
state: Tuple[_FuncVar, Callable[[_Func], None]] = hooks.use_state(
144-
lambda: initial_func
145-
)
141+
def _use_callable(initial_func: _Func) -> Tuple[_Func, Callable[[_Func], None]]:
142+
state = hooks.use_state(lambda: initial_func)
146143
return state[0], lambda new: state[1](lambda old: new)
147144

148145

0 commit comments

Comments
 (0)