Description
When calling pygame.event.get() with a sequence of event types using the eventtype keyword the return values are sorted by event type rather than preserving their order in the queue. This works fine when only one event type is pass but it problematic when asking for multiple types. Events returned by this function should not be reordered. The docs do not mention reordering and it does not seem like wanted behavior when dealing with events as order inherently matters when dealing with a queue.
On a side not, the eventtype kwarg does not accept sets of events and only takes sequences. It would be nice to allow for sets to be used as well as lists.
I did not test if using the exclude functionality would result in events being sorted as well.
Environment:
pygame-ce 2.5.2 (SDL 2.30.8, Python 3.12.0)
Current behavior:
Events are returned sorted by event type.
Expected behavior:
Events to return in the same order as they exist in the queue regardless of type.
Test code
pygame.init()
# define custom events
USEREVENT_1 = pygame.event.custom_type()
USEREVENT_2 = pygame.event.custom_type()
# post custom events
pygame.event.post(pygame.event.Event(USEREVENT_1, {'message': 'First Event 1'}))
pygame.event.post(pygame.event.Event(USEREVENT_2, {'message': 'First Event 2'}))
pygame.event.post(pygame.event.Event(USEREVENT_1, {'message': 'Second Event 1'}))
# user events
userevent_types = [USEREVENT_1, USEREVENT_2]
# print the events in the order returned
for event in pygame.event.get(eventtype = userevent_types):
print(f'Message: {event.message}')
pygame.quit()