From f1a8c74649f35da1ed99c2df5e33527ff99c1076 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Tue, 6 Sep 2022 10:23:28 +0100 Subject: [PATCH] remove copose idea --- src/textual/_compose.py | 44 ----------------------------------------- src/textual/app.py | 6 +----- src/textual/widget.py | 6 +----- 3 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 src/textual/_compose.py diff --git a/src/textual/_compose.py b/src/textual/_compose.py deleted file mode 100644 index 0a2a01754..000000000 --- a/src/textual/_compose.py +++ /dev/null @@ -1,44 +0,0 @@ -from __future__ import annotations - -from types import GeneratorType -from typing import TYPE_CHECKING, Iterable - -if TYPE_CHECKING: - from .app import ComposeResult - from .widget import Widget - - -def _compose(compose_result: ComposeResult) -> Iterable[Widget]: - """Turns a compose result in to an iterable of Widgets. - - If `compose_result` is a generator, this will run the generator and send - back the yielded widgets. This allows you to write code such as this: - - ```python - yes = yield Button("Yes") - yes.variant = "success" - ``` - - Otherwise `compose_result` is assumed to already be an iterable of Widgets - and will be returned unmodified. - - Args: - compose_result (ComposeResult): Either an iterator of widgets, - or a generator. - - Returns: - Iterable[Widget]: An iterable if widgets. - - """ - - if isinstance(compose_result, GeneratorType): - try: - widget = next(compose_result) - send = compose_result.send - while True: - yield widget - widget = send(widget) - except StopIteration: - pass - else: - yield from compose_result diff --git a/src/textual/app.py b/src/textual/app.py index 62acf53b5..5fb4c814b 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -15,7 +15,6 @@ from typing import Any, Generator, Generic, Iterable, Iterator, Type, TypeVar, c from weakref import WeakSet, WeakValueDictionary from ._ansi_sequences import SYNC_END, SYNC_START -from ._compose import _compose from ._path import _make_path_object_relative if sys.version_info >= (3, 8): @@ -386,9 +385,6 @@ class App(Generic[ReturnType], DOMNode): return yield - def _compose(self) -> Iterable[Widget]: - return _compose(self.compose()) - def get_css_variables(self) -> dict[str, str]: """Get a mapping of variables used to pre-populate CSS. @@ -1149,7 +1145,7 @@ class App(Generic[ReturnType], DOMNode): self.set_timer(screenshot_timer, on_screenshot, name="screenshot timer") def _on_mount(self) -> None: - widgets = self._compose() + widgets = self.compose() if widgets: self.mount_all(widgets) diff --git a/src/textual/widget.py b/src/textual/widget.py index 63a332447..a97f8b129 100644 --- a/src/textual/widget.py +++ b/src/textual/widget.py @@ -18,7 +18,6 @@ from rich.text import Text from . import errors, events, messages from ._animator import BoundAnimator from ._arrange import DockArrangeResult, arrange -from ._compose import _compose from ._context import active_app from ._layout import Layout from ._segment_tools import align_lines @@ -268,9 +267,6 @@ class Widget(DOMNode): return yield - def _compose(self) -> Iterable[Widget]: - return _compose(self.compose()) - def _post_register(self, app: App) -> None: """Called when the instance is registered. @@ -1456,7 +1452,7 @@ class Widget(DOMNode): await self.dispatch_key(event) def _on_mount(self, event: events.Mount) -> None: - widgets = self._compose() + widgets = self.compose() self.mount(*widgets) self.screen.refresh(repaint=False, layout=True)