-
-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove event.peek() behavior, minor doc and stub fixes #3122
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR!
Worth to mention that @gresm also proposed a fix for this issue in his latest PR.
Otherwise, I left little changes.
dcf5de2
to
5d6efb6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is becoming public, a test or two for it would also be good
buildconfig/stubs/pygame/event.pyi
Outdated
exclude: Optional[_EventTypes] = None, | ||
) -> List[Event]: ... | ||
def poll() -> Event: ... | ||
def wait(timeout: int = 0) -> Event: ... | ||
def peek(eventtype: Optional[_EventTypes] = None, pump: Any = True) -> bool: ... | ||
def clear(eventtype: Optional[_EventTypes] = None, pump: Any = True) -> None: ... | ||
def peek(eventtype: Optional[_EventTypes] = None, pump: bool = True) -> bool: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return value probably needs to be updated here to be consistent with the docs.
Also, the reason it was typed as Any
in the first place is because almost any object in python is acceptable as a bool, as you probably already know
Wanted to write one for it, but got a segfault with this code: import pygame
pygame.init()
pygame.event.clear()
e = pygame.Event(pygame.KEYDOWN, key=pygame.K_SPACE)
pygame.event.post(e)
print("1")
assert e == pygame.event.peek(pump=False)
print("2")
assert e == pygame.event.peek(None, False)
print("3") # This one never gets printed Debugging it a bit more, seems like the dict proxy on this line is already freed Line 930 in ddc900e
|
After giving it a bit of thought, my current opinion is that we should remove this functionality all together now.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a bit of confusion here, what I actually wanted to convey was "make the return value a bool regardless of the input, just remove the behaviour of returning an event type". I would still like to retain the None
/optional-arg case
Fixes #1196 by documenting the behavior of pygame.event.peek if nothing is passed in.
Also marks
event.type
andevent.dict
readonly in the stubs, adds runtime docs to them, and makes the pump argument more accurate in the stubs.