Skip to content

[Typing] Add type hint to sender in widget messages? #1813

@rodrigogiraoserrao

Description

@rodrigogiraoserrao

The class Message defines the attribute sender as being of the type MessageTarget, which is a fairly generic protocol. Fine.

When writing custom messages, wouldn't it make sense to add an explicit type hint to mark the class variable sender as being of the type of the widget within which the message is being defined?

E.g., won't this make sense:

class MyWidget(Widget):
   class MyMessage(Message):

        sender: MyWidget  # Isn't this something sensible to do?

        def __init__(self, sender: MyWidget, ...):
            ...

By adding sender: MyWidget in the body of the class, IDEs and static checkers will let me make use of .sender as of being the type I already know it is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions