diff --git a/docs/examples/app/question02.py b/docs/examples/app/question02.py index 444eaebae..7efb0f2f6 100644 --- a/docs/examples/app/question02.py +++ b/docs/examples/app/question02.py @@ -5,9 +5,9 @@ from textual.widgets import Static, Button class QuestionApp(App[str]): def compose(self) -> ComposeResult: yield Static("Do you love Textual?") - yield (yes := Button("Yes", id="yes")) + yes = yield Button("Yes", id="yes") yes.variant = "primary" - yield (no := Button("No", id="no")) + no = yield Button("No", id="no") no.variant = "error" def on_button_pressed(self, event: Button.Pressed) -> None: diff --git a/src/textual/_compose.py b/src/textual/_compose.py index 9e61cf577..0a2a01754 100644 --- a/src/textual/_compose.py +++ b/src/textual/_compose.py @@ -4,7 +4,6 @@ from types import GeneratorType from typing import TYPE_CHECKING, Iterable if TYPE_CHECKING: - from .app import ComposeResult from .widget import Widget @@ -28,17 +27,18 @@ def _compose(compose_result: ComposeResult) -> Iterable[Widget]: or a generator. Returns: - Iterable[Widget]: In iterable if widgets. + Iterable[Widget]: An iterable if widgets. """ - if not isinstance(compose_result, GeneratorType): - return compose_result - - try: - widget = next(compose_result) - while True: - yield widget - widget = compose_result.send(widget) - except StopIteration: - pass + 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