Skip to content
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

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Document event.peek behaviour, minor doc and stub fixes
zoldalma999 committed Sep 28, 2024
commit 5d6efb68e11ba90224d80db575e0869310a9a6aa
12 changes: 7 additions & 5 deletions buildconfig/stubs/pygame/event.pyi
Original file line number Diff line number Diff line change
@@ -11,8 +11,10 @@ from pygame.typing import SequenceLike

@final
class Event:
type: int
dict: Dict[str, Any]
@property
def type(self) -> int: ...
@property
def dict(self) -> Dict[str, Any]: ...
__dict__: Dict[str, Any]
__hash__: None # type: ignore
def __init__(
@@ -28,13 +30,13 @@ _EventTypes = Union[int, SequenceLike[int]]
def pump() -> None: ...
def get(
eventtype: Optional[_EventTypes] = None,
pump: Any = True,
pump: bool = True,
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: ...
MyreMylar marked this conversation as resolved.
Show resolved Hide resolved
def clear(eventtype: Optional[_EventTypes] = None, pump: bool = True) -> None: ...
def event_name(type: int, /) -> str: ...
def set_blocked(type: Optional[_EventTypes], /) -> None: ...
def set_allowed(type: Optional[_EventTypes], /) -> None: ...
8 changes: 6 additions & 2 deletions docs/reST/ref/event.rst
Original file line number Diff line number Diff line change
@@ -317,10 +317,14 @@ On Android, the following events can be generated
.. function:: peek

| :sl:`test if event types are waiting on the queue`
| :sg:`peek() -> Event`
| :sg:`peek(eventtype=None) -> bool`
| :sg:`peek(eventtype=None, pump=True) -> bool`

Returns ``True`` if there are any events of the given type waiting on the
If the ``eventtype`` argument is not passed or is ``None`` (the default), returns
the next event on the queue.

Otherwise it returns whether there's any events of the given type waiting on the
queue. If a sequence of event types is passed, this will return ``True`` if
any of those events are on the queue.

@@ -491,7 +495,7 @@ On Android, the following events can be generated

Read-only. The event type identifier. For user created event
objects, this is the ``type`` argument passed to
:func:`pygame.event.Event()`.
:class:`pygame.event.Event()`.

For example, some predefined event identifiers are ``QUIT`` and
``MOUSEMOTION``.
2 changes: 1 addition & 1 deletion src_c/doc/event_doc.h
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
#define DOC_EVENT_GET "get(eventtype=None) -> Eventlist\nget(eventtype=None, pump=True) -> Eventlist\nget(eventtype=None, pump=True, exclude=None) -> Eventlist\nget events from the queue"
#define DOC_EVENT_POLL "poll() -> Event instance\nget a single event from the queue"
#define DOC_EVENT_WAIT "wait() -> Event instance\nwait(timeout) -> Event instance\nwait for a single event from the queue"
#define DOC_EVENT_PEEK "peek(eventtype=None) -> bool\npeek(eventtype=None, pump=True) -> bool\ntest if event types are waiting on the queue"
#define DOC_EVENT_PEEK "peek() -> Event\npeek(eventtype=None) -> bool\npeek(eventtype=None, pump=True) -> bool\ntest if event types are waiting on the queue"
#define DOC_EVENT_CLEAR "clear(eventtype=None) -> None\nclear(eventtype=None, pump=True) -> None\nremove all events from the queue"
#define DOC_EVENT_EVENTNAME "event_name(type, /) -> string\nget the string name from an event id"
#define DOC_EVENT_SETBLOCKED "set_blocked(type, /) -> None\nset_blocked(typelist, /) -> None\nset_blocked(None) -> None\ncontrol which events are blocked on the queue"
6 changes: 3 additions & 3 deletions src_c/event.c
Original file line number Diff line number Diff line change
@@ -1420,9 +1420,9 @@ static PyTypeObject pgEvent_Type;
#define OFF(x) offsetof(pgEventObject, x)

static PyMemberDef pg_event_members[] = {
{"__dict__", T_OBJECT, OFF(dict), READONLY},
{"type", T_INT, OFF(type), READONLY},
{"dict", T_OBJECT, OFF(dict), READONLY},
{"__dict__", T_OBJECT, OFF(dict), READONLY, DOC_EVENT_EVENT_DICT},
{"type", T_INT, OFF(type), READONLY, DOC_EVENT_EVENT_TYPE},
{"dict", T_OBJECT, OFF(dict), READONLY, DOC_EVENT_EVENT_DICT},
{NULL} /* Sentinel */
};