pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Add `__match_args__` to `Event` for `type`

Open aatle opened this issue 1 week ago • 3 comments
trafficstars

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

aatle avatar Nov 10 '25 05:11 aatle