3131from .timer import Timer , TimerCallback
3232
3333if TYPE_CHECKING :
34+ from typing_extensions import TypeAlias
35+
3436 from .app import App
3537 from .css .model import SelectorSet
3638
3739
40+ Callback : TypeAlias = "Callable[..., Any] | Callable[..., Awaitable[Any]]"
41+
42+
3843class CallbackError (Exception ):
3944 pass
4045
@@ -174,7 +179,7 @@ def has_parent(self) -> bool:
174179 return self ._parent is not None
175180
176181 @property
177- def app (self ) -> "App" :
182+ def app (self ) -> "App[object] " :
178183 """
179184 Get the current app.
180185
@@ -369,7 +374,7 @@ def set_interval(
369374 self ._timers .add (timer )
370375 return timer
371376
372- def call_after_refresh (self , callback : Callable , * args : Any , ** kwargs : Any ) -> bool :
377+ def call_after_refresh (self , callback : Callback , * args : Any , ** kwargs : Any ) -> bool :
373378 """Schedule a callback to run after all messages are processed and the screen
374379 has been refreshed. Positional and keyword arguments are passed to the callable.
375380
@@ -387,7 +392,7 @@ def call_after_refresh(self, callback: Callable, *args: Any, **kwargs: Any) -> b
387392 message = messages .InvokeLater (partial (callback , * args , ** kwargs ))
388393 return self .post_message (message )
389394
390- def call_later (self , callback : Callable , * args : Any , ** kwargs : Any ) -> bool :
395+ def call_later (self , callback : Callback , * args : Any , ** kwargs : Any ) -> bool :
391396 """Schedule a callback to run after all messages are processed in this object.
392397 Positional and keywords arguments are passed to the callable.
393398
@@ -404,7 +409,7 @@ def call_later(self, callback: Callable, *args: Any, **kwargs: Any) -> bool:
404409 message = events .Callback (callback = partial (callback , * args , ** kwargs ))
405410 return self .post_message (message )
406411
407- def call_next (self , callback : Callable , * args : Any , ** kwargs : Any ) -> None :
412+ def call_next (self , callback : Callback , * args : Any , ** kwargs : Any ) -> None :
408413 """Schedule a callback to run immediately after processing the current message.
409414
410415 Args:
0 commit comments