Skip to content

compose method and yields #3698

Answered by willmcgugan
stefanoborini asked this question in Q&A
Discussion options

You must be logged in to vote

The generator approach is more expressive, and easier to edit. The natural indentation of the with block expresses nesting without the need for so much parenthesis. It also allows you to express dynamic constructs more naturally.

Adding logic is quite natural with the generator approach, but more awkward with a list.

with Parent():
    if show_children:
        with Child():
            for child in range(kid_count):
                yield Grandchild(id=f"kid{child}")

But all that is required is for it to return an iterable of Widgets. So as @davep pointed out, you are free to return a list.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@stefanoborini
Comment options

@willmcgugan
Comment options

Answer selected by stefanoborini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #3696 on November 17, 2023 12:09.