Skip to content

@on decorator matches widget subclass unexpectedly #4968

Open
@darrenburns

Description

@darrenburns

The code below fires a notification when you click the button.

from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Button


class MyButton(Button):
    pass


class MyApp(App[None]):
    def compose(self) -> ComposeResult:
        yield Button("Normal Button")

    @on(MyButton.Pressed)
    def notify_on_press_my_button(self) -> None:
        self.notify("MyButton.Pressed matched!")


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

On clicking a Button, I would not expect a handler decorated with @on(MyButton.Pressed) to fire.

If I click a MyButton, I'd expect a @on(Button.Pressed) handler to fire, and I've confirmed this works as I expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions