Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Children can be added to ALLOW_CHILDREN=False widgets #3781

Closed
davep opened this issue Nov 29, 2023 · 2 comments
Closed

Children can be added to ALLOW_CHILDREN=False widgets #3781

davep opened this issue Nov 29, 2023 · 2 comments
Labels
bug Something isn't working enhancement New feature or request Task

Comments

@davep
Copy link
Contributor

davep commented Nov 29, 2023

Raising this after going over it during the close of 2023-11-29 standup

Following on from #3758, which ALLOW_CHILDREN was introduced, and where code like this:

from textual.app import App, ComposeResult
from textual.widgets import Static

class NoChildren1(App[None]):

    def compose(self) -> ComposeResult:
        with Static():
            yield Static("Hello")

if __name__ == "__main__":
    NoChildren1().run()

will not result in a NotAContainer exception... it is still possible to treat such a widget as a container, either by inheriting from it and composing in the widgets:

from textual.app import App, ComposeResult
from textual.widgets import Static

class DodgyStatic(Static):

    def compose(self) -> ComposeResult:
        yield Static("Hello")

class NoChildren2(App[None]):

    def compose(self) -> ComposeResult:
        yield DodgyStatic()

if __name__ == "__main__":
    NoChildren2().run()

by mounting widgets into it:

from textual.app import App, ComposeResult
from textual.widgets import Static

class NoChildren3(App[None]):

    def compose(self) -> ComposeResult:
        yield Static()

    def on_mount(self) -> None:
        self.query_one(Static).mount(Static("Hello"))

if __name__ == "__main__":
    NoChildren3().run()

or by passing children to a widget that accepts children but has ALLOW_CHILDREN=False:

from textual.app import App, ComposeResult
from textual.widget import Widget
from textual.widgets import Static

class NotACounter(Widget):
    ALLOW_CHILDREN = False

class NoChildren4(App[None]):

    def compose(self) -> ComposeResult:
        yield NotACounter(Static("Hello"))

if __name__ == "__main__":
    NoChildren4().run()

If ALLOW_CHILDREN were to affect all these cases it would also mean that feature would pretty much satisfy (albeit there would be a need for an internal override) a long-standing issue: #2210 (which in turn goes back a bit further).

@willmcgugan
Copy link
Collaborator

Redundant now, since we reversed the ALLOW_CHILDREN idea.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Task
Projects
None yet
Development

No branches or pull requests

2 participants