Skip to content

Commit 487c380

Browse files
try to please mypy
1 parent 71db1fc commit 487c380

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

nicegui/event.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
from .logging import log
1818
from .slot import Slot
1919

20+
P = ParamSpec('P')
21+
2022

2123
@dataclass(**KWONLY_SLOTS)
22-
class Callback:
23-
func: Callable
24+
class Callback(Generic[P]):
25+
func: Callable[P, Any] | Callable[[], Any]
2426
filepath: str
2527
line: int
2628
slot: weakref.ref[Slot] | None = None
@@ -36,14 +38,11 @@ async def await_result(self, result: Awaitable | AwaitableResponse | asyncio.Tas
3638
return await result
3739

3840

39-
P = ParamSpec('P')
40-
41-
4241
class Event(Generic[P]):
4342
instances: ClassVar[list[Event]] = []
4443

4544
def __init__(self) -> None:
46-
self.callbacks: list[Callback] = []
45+
self.callbacks: list[Callback[P]] = []
4746
self.instances.append(self)
4847

4948
def subscribe(self, callback: Callable[P, Any] | Callable[[], Any]) -> None:
@@ -126,7 +125,7 @@ def __await__(self):
126125
return self.emitted().__await__()
127126

128127

129-
def _invoke_and_forget(callback: Callback, *args: P.args, **kwargs: P.kwargs) -> Any:
128+
def _invoke_and_forget(callback: Callback[P], *args: P.args, **kwargs: P.kwargs) -> Any:
130129
try:
131130
result = callback.run(*args, **kwargs)
132131
if _should_await(result):
@@ -138,7 +137,7 @@ def _invoke_and_forget(callback: Callback, *args: P.args, **kwargs: P.kwargs) ->
138137
log.exception('Could not emit callback %s', callback)
139138

140139

141-
async def _invoke_and_await(callback: Callback, *args: P.args, **kwargs: P.kwargs) -> Any:
140+
async def _invoke_and_await(callback: Callback[P], *args: P.args, **kwargs: P.kwargs) -> Any:
142141
try:
143142
result = callback.run(*args, **kwargs)
144143
if _should_await(result):

0 commit comments

Comments
 (0)