3131
3232from .driver import InputDriver
3333
34+ # Needed for Python 3.11 compatibility,
35+ # as "int() in MyIntEnumSubclass" wasn't available until Python 3.12
36+ _DEVICEID_ANALOG_MEMBERS = DeviceIdAnalog .__members__ .values ()
37+ _DEVICEID_JOYPAD_MEMBERS = DeviceIdJoypad .__members__ .values ()
38+ _DEVICEID_LIGHTGUN_MEMBERS = DeviceIdLightgun .__members__ .values ()
39+ _DEVICEID_MOUSE_MEMBERS = DeviceIdMouse .__members__ .values ()
40+ _KEY_MEMBERS = Key .__members__ .values ()
41+
3442
3543@dataclass (order = True , slots = True )
3644class Point :
@@ -279,7 +287,7 @@ def _lookup_port_state(
279287 InputDevice .JOYPAD ,
280288 _,
281289 id ,
282- ) if id in DeviceIdJoypad :
290+ ) if id in _DEVICEID_JOYPAD_MEMBERS :
283291 # When asking for a specific joypad button,
284292 # return 1 (True) if its pressed and 0 (False) if not
285293 # NOTE: id in DeviceInJoypad is perfectly valid
@@ -327,15 +335,15 @@ def _lookup_port_state(
327335 InputDevice .ANALOG ,
328336 DeviceIndexAnalog .LEFT ,
329337 id ,
330- ) if ( id in DeviceIdAnalog ) :
338+ ) if id in _DEVICEID_ANALOG_MEMBERS :
331339 analog_state : AnalogState
332340 return analog_state .lstick [id ]
333341 case (
334342 AnalogState () as analog_state ,
335343 InputDevice .ANALOG ,
336344 DeviceIndexAnalog .RIGHT ,
337345 id ,
338- ) if ( id in DeviceIdAnalog ) :
346+ ) if id in _DEVICEID_ANALOG_MEMBERS :
339347 analog_state : AnalogState
340348 return analog_state .rstick [id ]
341349 case AnalogState (), _, _, _:
@@ -349,7 +357,7 @@ def _lookup_port_state(
349357 InputDevice .MOUSE ,
350358 _,
351359 id ,
352- ) if id in DeviceIdMouse :
360+ ) if id in _DEVICEID_MOUSE_MEMBERS :
353361 # When asking for a specific mouse button,
354362 # return 1 (True) if its pressed and 0 (False) if not
355363 mouse_state : MouseState
@@ -382,7 +390,7 @@ def _lookup_port_state(
382390 InputDevice .KEYBOARD ,
383391 _,
384392 id ,
385- ) if id in Key :
393+ ) if id in _KEY_MEMBERS :
386394 # KeyboardState overloads __getitem__ to return True for pressed keys
387395 # and False for unpressed or invalid keys.
388396 return keyboard_state [id ]
@@ -391,7 +399,7 @@ def _lookup_port_state(
391399 return 0
392400
393401 # Yielding a Key value will expose it as a key press on the keyboard device.
394- case Key (key ), InputDevice .KEYBOARD , _, id if key == id and id in Key :
402+ case Key (key ), InputDevice .KEYBOARD , _, id if key == id and id in _KEY_MEMBERS :
395403 return 1
396404 case Key (_), _, _, _: # When yielding a Key in all other cases, return 0
397405 return 0
@@ -400,7 +408,7 @@ def _lookup_port_state(
400408 # with all other devices defaulting to 0.
401409 # Index is ignored.
402410 case LightGunState () as light_gun_state , InputDevice .LIGHTGUN , _, id if (
403- id in DeviceIdLightgun
411+ id in _DEVICEID_LIGHTGUN_MEMBERS
404412 ):
405413 light_gun_state : LightGunState
406414 return light_gun_state [id ]
0 commit comments