Skip to content

Commit 059f602

Browse files
authored
Small optimization in checking event type (#84)
1 parent 8663485 commit 059f602

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

rendercanvas/_events.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class EventType(BaseEnum):
4242
animate = None #: Animation event. Has 'step' representing the step size in seconds. This is stable, except when the 'catch_up' field is nonzero.
4343

4444

45+
valid_event_types = set(EventType)
46+
47+
4548
class EventEmitter:
4649
"""The EventEmitter stores event handlers, collects incoming events, and dispatched them.
4750
@@ -127,7 +130,7 @@ def my_handler(event):
127130
for type in types:
128131
if not isinstance(type, str):
129132
raise TypeError(f"Event types must be str, but got {type}")
130-
if not (type == "*" or type in EventType):
133+
if not (type == "*" or type in valid_event_types):
131134
raise ValueError(f"Adding handler with invalid event_type: '{type}'")
132135

133136
def decorator(_callback):
@@ -168,7 +171,7 @@ def submit(self, event):
168171
if self._closed:
169172
return
170173
event_type = event["event_type"]
171-
if event_type not in EventType:
174+
if event_type not in valid_event_types:
172175
raise ValueError(f"Submitting with invalid event_type: '{event_type}'")
173176

174177
event.setdefault("time_stamp", time.perf_counter())

0 commit comments

Comments
 (0)