Skip to content

Commit 434ed57

Browse files
authored
Hotfix threaded loading examples and sections issue #2499 (#2503)
* Fix threaded_loading example fighting for definition of `time` during testing * (#2499) Allow for Falsey values for preventing dispatch in Sections * linting pass * modify sections to accept bools for `prevent_dispatch` and `prevent_dispatch_view`
1 parent 9aa8e1a commit 434ed57

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

arcade/examples/threaded_loading.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from __future__ import annotations
3030

3131
import sys
32-
import time
32+
from time import sleep
3333

3434
# Python's threading module has proven tools for working with threads, and
3535
# veteran developers may want to explore 3.13's new 'No-GIL' concurrency.
@@ -104,7 +104,7 @@ def _load_levels(self):
104104
with self._interaction_lock:
105105
self._current_level = level
106106

107-
time.sleep(ARTIFICIAL_DELAY) # "Slow" down (delete this line before use)
107+
sleep(ARTIFICIAL_DELAY) # "Slow" down (delete this line before use)
108108

109109
# Since unhandled exceptions "kill" threads, we catch the only major
110110
# exception we expect. Level 4 is intentionally missing to test cases

arcade/sections.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def __init__(
6464
name: str | None = None,
6565
accept_keyboard_keys: bool | Iterable = True,
6666
accept_mouse_events: bool | Iterable = True,
67-
prevent_dispatch: Iterable | None = None,
68-
prevent_dispatch_view: Iterable | None = None,
67+
prevent_dispatch: Iterable | bool | None = None,
68+
prevent_dispatch_view: Iterable | bool | None = None,
6969
local_mouse_coordinates: bool = False,
7070
enabled: bool = True,
7171
modal: bool = False,
@@ -96,10 +96,18 @@ def __init__(
9696
self.accept_mouse_events: bool | Iterable = accept_mouse_events
9797
"""Arcade mouse events to accept."""
9898

99-
self.prevent_dispatch: Iterable = prevent_dispatch or {True}
99+
if isinstance(prevent_dispatch, bool):
100+
prevent_dispatch = {prevent_dispatch}
101+
self.prevent_dispatch: Iterable = {True} if prevent_dispatch is None else prevent_dispatch
102+
assert isinstance(self.prevent_dispatch, Iterable)
100103
"""prevents events to propagate"""
101104

102-
self.prevent_dispatch_view: Iterable = prevent_dispatch_view or {True}
105+
if isinstance(prevent_dispatch_view, bool):
106+
prevent_dispatch_view = {prevent_dispatch_view}
107+
self.prevent_dispatch_view: Iterable = (
108+
{True} if prevent_dispatch_view is None else prevent_dispatch_view
109+
)
110+
assert isinstance(self.prevent_dispatch_view, Iterable)
103111
"""prevents events to propagate to the view"""
104112

105113
self.local_mouse_coordinates: bool = local_mouse_coordinates

0 commit comments

Comments
 (0)