Skip to content

Add __match_args__ to Event for typeย #3642

@aatle

Description

@aatle

match statements are good for pygame events.

match event:
    case Event(type=pygame.MOUSEBUTTONDOWN, pos=(x, y)):
        print(x, y)

(Maybe that should be documented.)

If __match_args__ = ("type,") was added to Event, then type would be positional so that type= doesn't need to be written:

match event:
    case Event(pygame.MOUSEBUTTONDOWN, pos=(x, y)):
        print(x, y)

__match_args__ could also be added to classes like Rect and Vector2/3 but I don't think there are many use cases.

https://docs.python.org/3/tutorial/controlflow.html#match-statements

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions