From 52ac87ac29bd797d7d4372997e6df23b0509d039 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Thu, 30 May 2024 16:25:50 +0100 Subject: [PATCH] restore sanity check --- src/textual/app.py | 5 +++-- src/textual/timer.py | 7 ++++++- src/textual/widget.py | 1 - 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/textual/app.py b/src/textual/app.py index a19d71b588..4cda806968 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -3362,10 +3362,11 @@ async def _prune_nodes(self, widgets: list[Widget]) -> None: Args: widgets: Widgets to remove. """ + if not self.is_attached: + return async with self._dom_lock: for widget in widgets: - if self.is_attached: - await self._prune_node(widget) + await self._prune_node(widget) async def _prune_node(self, root: Widget) -> None: """Remove a node and its children. Children are removed before parents. diff --git a/src/textual/timer.py b/src/textual/timer.py index 0dffc7fc9a..3845e0183c 100644 --- a/src/textual/timer.py +++ b/src/textual/timer.py @@ -104,7 +104,12 @@ async def _stop_all(cls, timers: Iterable[Timer]) -> None: timers: A number of timers. """ - async def stop_timer(timer) -> None: + async def stop_timer(timer: Timer) -> None: + """Stop a timer and wait for it to finish. + + Args: + timer: A Timer instance. + """ if timer._task is not None: timer._active.set() timer._task.cancel() diff --git a/src/textual/widget.py b/src/textual/widget.py index e7e87ecbf4..459a64e5c4 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -935,7 +935,6 @@ def mount( provided a ``MountError`` will be raised. """ if not self.is_attached: - return AwaitMount(self, []) raise MountError(f"Can't mount widget(s) before {self!r} is mounted") # Check for duplicate IDs in the incoming widgets ids_to_mount = [widget.id for widget in widgets if widget.id is not None]