Skip to content

Commit 8680024

Browse files
committed
Fix formatting for docs and bugfixes.
1 parent e8e9a42 commit 8680024

File tree

7 files changed

+106
-47
lines changed

7 files changed

+106
-47
lines changed

buildconfig/stubs/pygame/_event.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3-
from ._common import Sequence, EventLike
3+
from .typing import SequenceLike, EventLike
44

5-
_EventTypes = int | Sequence[int]
5+
_EventTypes = int | SequenceLike[int]
66

77
def pump(dopump: bool, /) -> None: ...
88
def get(

buildconfig/stubs/pygame/event.pyi

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,26 @@
1-
from __future__ import annotations
1+
from typing import Any, Union, Optional
22

3-
from typing import Any, Protocol
3+
from pygame.typing import SequenceLike, EventLike
44

5-
from pygame.typing import SequenceLike
65

7-
# TODO: Should this be moved to "pygame.typing"?
6+
class Event(EventLike):
7+
def __new__(cls, *args: Any, **kwargs: Any) -> "Event": ...
88

9-
class _EventLike(Protocol):
10-
def __init__(
11-
self, type: int, dict: dict[str, Any] | None = None, **kwargs: Any
12-
) -> None: ...
13-
def __getattribute__(self, name: str) -> Any: ...
14-
def __setattr__(self, name: str, value: Any) -> None: ...
15-
def __delattr__(self, name: str) -> None: ...
16-
def __int__(self) -> int: ...
17-
def __bool__(self) -> bool: ...
18-
def __eq__(self, other: Any) -> bool: ...
19-
20-
@property
21-
def type(self) -> int: ...
22-
@property
23-
def dict(self) -> dict[str, Any]: ...
24-
25-
26-
class Event(_EventLike):
27-
...
28-
29-
_EventTypes = int | SequenceLike[int]
9+
_EventTypes = Union[int, SequenceLike[int]]
3010

3111
def pump() -> None: ...
3212
def get(
33-
eventtype: _EventTypes | None = None,
13+
eventtype: Optional[_EventTypes] = None,
3414
pump: Any = True,
35-
exclude: _EventTypes | None = None,
15+
exclude: Optional[_EventTypes] = None,
3616
) -> list[Event]: ...
3717
def poll() -> Event: ...
3818
def wait(timeout: int = 0) -> Event: ...
39-
def peek(eventtype: _EventTypes | None = None, pump: Any = True) -> bool: ...
40-
def clear(eventtype: _EventTypes | None = None, pump: Any = True) -> None: ...
19+
def peek(eventtype: Optional[_EventTypes] = None, pump: Any = True) -> bool: ...
20+
def clear(eventtype: Optional[_EventTypes] = None, pump: Any = True) -> None: ...
4121
def event_name(type: int) -> str: ...
42-
def set_blocked(type: _EventTypes | None, *args: int) -> None: ...
43-
def set_allowed(type: _EventTypes | None, *args: int) -> None: ...
22+
def set_blocked(type: Optional[_EventTypes], *args: int) -> None: ...
23+
def set_allowed(type: Optional[_EventTypes], *args: int) -> None: ...
4424
def get_blocked(type: _EventTypes, *args: int) -> bool: ...
4525
def set_grab(grab: bool, /) -> None: ...
4626
def get_grab() -> bool: ...

buildconfig/stubs/pygame/typing.pyi

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Use the command `python buildconfig/stubs/gen_stubs.py` to copy typing.py to typing.pyi
55

66
import sys
7-
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex
7+
from typing import IO, Callable, Tuple, Dict, Union, Optional, TypeVar, Protocol, SupportsIndex, Any
88

99
if sys.version_info >= (3, 9):
1010
from os import PathLike as _PathProtocol
@@ -55,5 +55,24 @@ class _HasRectAttribute(Protocol):
5555

5656
RectLike = Union[_CanBeRect, _HasRectAttribute]
5757

58+
59+
class EventLike(Protocol):
60+
def __init__(
61+
self, type: int, dict: Optional[Dict[str, Any]] = None, **kwargs: Any
62+
) -> None: ...
63+
def __new__(cls, *args: Any, **kwargs: Any) -> "EventLike": ...
64+
def __getattribute__(self, name: str) -> Any: ...
65+
def __setattr__(self, name: str, value: Any) -> None: ...
66+
def __delattr__(self, name: str) -> None: ...
67+
def __int__(self) -> int: ...
68+
def __bool__(self) -> bool: ...
69+
def __eq__(self, other: Any) -> bool: ...
70+
71+
@property
72+
def type(self) -> int: ...
73+
@property
74+
def dict(self) -> Dict[str, Any]: ...
75+
76+
5877
# cleanup namespace
59-
del sys, IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex
78+
del sys, IO, Callable, Tuple, Dict, Union, TypeVar, Protocol, SupportsIndex

src_c/_event.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,13 +678,13 @@ pgEvent_AutoInit(PyObject *self, PyObject *_null)
678678
static int
679679
pg_post_event(int type, PyObject *obj)
680680
{
681+
if (type == -1)
682+
return -1;
683+
681684
SDL_Event event = {0};
682685

683686
event.type = _pg_pgevent_proxify(type);
684687

685-
if (event.type == -1)
686-
return -1;
687-
688688
if (obj)
689689
Py_INCREF(obj);
690690

src_c/time.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ timer_callback(Uint32 interval, void *param)
264264
}
265265
else {
266266
if (SDL_WasInit(SDL_INIT_VIDEO)) {
267-
PyGILState_STATE gstate;
267+
PyGILState_STATE gstate = 0;
268268

269269
if (evtimer->obj)
270270
gstate = PyGILState_Ensure();

src_py/event.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@
105105

106106

107107
def event_name(type: int) -> str:
108-
"event_name(type, /) -> string\nget the string name from an event id"
108+
"""
109+
event_name(type, /) -> string
110+
111+
get the string name from an event id
112+
"""
109113

110114
if type in _NAMES_MAPPING:
111115
return _NAMES_MAPPING[type]
@@ -118,6 +122,7 @@ class Event:
118122
"""
119123
Event(type, dict) -> Event
120124
Event(type, **attributes) -> Event
125+
121126
pygame object for representing events
122127
"""
123128

@@ -208,7 +213,11 @@ def quit():
208213

209214

210215
def custom_type():
211-
"""custom_type() -> int\nmake custom user event type"""
216+
"""
217+
custom_type() -> int
218+
219+
make custom user event type
220+
"""
212221
global _custom_event
213222

214223
if _custom_event >= pg.NUMEVENTS:
@@ -219,7 +228,11 @@ def custom_type():
219228

220229

221230
def pump():
222-
"pump() -> None\ninternally process pygame event handlers"
231+
"""
232+
pump() -> None
233+
234+
internally process pygame event handlers
235+
"""
223236
return _pump(True)
224237

225238

@@ -252,19 +265,36 @@ def _setter(val: bool, type: int | Iterable[int] | None, *args: int):
252265

253266

254267
def set_blocked(type: int | Iterable[int] | None, *args: int):
255-
"set_blocked(type, /) -> None\nset_blocked(typelist, /) -> None\nset_blocked(None) -> None\ncontrol which events are blocked on the queue"
268+
"""
269+
set_blocked(type, /) -> None
270+
set_blocked(typelist, /) -> None
271+
set_blocked(None) -> None
272+
273+
control which events are blocked on the queue
274+
"""
256275

257276
_setter(False, type, *args)
258277

259278

260279
def set_allowed(type: int | Iterable[int] | None, *args: int):
261-
"set_allowed(type, /) -> None\nset_allowed(typelist, /) -> None\nset_allowed(None) -> None\ncontrol which events are allowed on the queue"
280+
"""
281+
set_allowed(type, /) -> None
282+
set_allowed(typelist, /) -> None
283+
set_allowed(None) -> None
284+
285+
control which events are allowed on the queue
286+
"""
262287

263288
_setter(True, type, *args)
264289

265290

266291
def get_blocked(type: int | Iterable[int], *args: int):
267-
"get_blocked(type, /) -> bool\nget_blocked(typelist, /) -> bool\ntest if a type of event is blocked from the queue"
292+
"""
293+
get_blocked(type, /) -> bool
294+
get_blocked(typelist, /) -> bool
295+
296+
test if a type of event is blocked from the queue
297+
"""
268298

269299
for t in _parse(type, args):
270300
if not _allowed_get(t):

src_py/typing.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
# Use the command `python buildconfig/stubs/gen_stubs.py` to copy typing.py to typing.pyi
55

66
import sys
7-
from typing import IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex
7+
from typing import (
8+
IO,
9+
Callable,
10+
Tuple,
11+
Dict,
12+
Union,
13+
Optional,
14+
TypeVar,
15+
Protocol,
16+
SupportsIndex,
17+
Any,
18+
)
819

920
if sys.version_info >= (3, 9):
1021
from os import PathLike as _PathProtocol
@@ -55,5 +66,24 @@ class _HasRectAttribute(Protocol):
5566

5667
RectLike = Union[_CanBeRect, _HasRectAttribute]
5768

69+
70+
class EventLike(Protocol):
71+
def __init__(
72+
self, type: int, dict: Optional[Dict[str, Any]] = None, **kwargs: Any
73+
) -> None: ...
74+
def __new__(cls, *args: Any, **kwargs: Any) -> "EventLike": ...
75+
def __getattribute__(self, name: str) -> Any: ...
76+
def __setattr__(self, name: str, value: Any) -> None: ...
77+
def __delattr__(self, name: str) -> None: ...
78+
def __int__(self) -> int: ...
79+
def __bool__(self) -> bool: ...
80+
def __eq__(self, other: Any) -> bool: ...
81+
82+
@property
83+
def type(self) -> int: ...
84+
@property
85+
def dict(self) -> Dict[str, Any]: ...
86+
87+
5888
# cleanup namespace
59-
del sys, IO, Callable, Tuple, Union, TypeVar, Protocol, SupportsIndex
89+
del sys, IO, Callable, Tuple, Dict, Union, TypeVar, Protocol, SupportsIndex

0 commit comments

Comments
 (0)