Skip to content

Commit

Permalink
allow None in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jul 24, 2024
1 parent d392768 commit 21db472
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
"""The result type of a screen."""

ScreenResultCallbackType = Union[
Callable[[ScreenResultType], None], Callable[[ScreenResultType], Awaitable[None]]
Callable[[ScreenResultType | None], None],
Callable[[ScreenResultType | None], Awaitable[None]],
]
"""Type of a screen result callback function."""

Expand Down Expand Up @@ -1244,8 +1245,7 @@ def dismiss(
message handler on the Screen being dismissed. If you want to dismiss the current screen, you can
call `self.dismiss()` _without_ awaiting.
If `result` is provided and a callback was set when the screen was [pushed][textual.app.App.push_screen], then
the callback will be invoked with `result`.
If `result` is not supplied, then the callback will be invoked with `None`.
Args:
result: The optional result to be passed to the result callback.
Expand All @@ -1255,8 +1255,10 @@ def dismiss(
if not self.is_active:
self.log.warning("Can't dismiss inactive screen")
return AwaitComplete()
if result is not self._NoResult and self._result_callbacks:
self._result_callbacks[-1](cast(ScreenResultType, result))
if self._result_callbacks:
self._result_callbacks[-1](
cast(ScreenResultType, None if result is self._NoResult else result)
)
await_pop = self.app.pop_screen()

def pre_await() -> None:
Expand Down

0 comments on commit 21db472

Please sign in to comment.