Skip to content

Commit 8a2e091

Browse files
committed
Release 0.1.9
1 parent dfb7b35 commit 8a2e091

File tree

6 files changed

+35
-12
lines changed

6 files changed

+35
-12
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
> breaking changes may be introduced
1111
> at any time without warning.
1212
13+
## [0.1.9] - 2024-06-07
14+
15+
### Fixed
16+
17+
- Remove some methods or other constructs that were added in Python 3.12,
18+
to ensure compatibility with Python 3.11.
19+
1320
## [0.1.8] - 2024-06-05
1421

1522
### Fixed

src/libretro/core.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
# TODO: Add a CorePhase enum that's updated when entering/leaving each phase.
3939
# (Some envcalls can only be called in certain phases, so this would be useful for error checking.)
4040

41+
_REGION_MEMBERS = Region.__members__.values()
42+
4143

4244
class CoreInterface(Protocol):
4345
"""
@@ -639,7 +641,7 @@ def get_region(self) -> Region | int:
639641
or as a plain ``int`` if not.
640642
"""
641643
region: int = self._core.retro_get_region()
642-
return Region(region) if region in Region else region
644+
return Region(region) if region in _REGION_MEMBERS else region
643645

644646
def get_memory_data(self, id: int) -> c_void_p | None:
645647
"""

src/libretro/drivers/environment/dict.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
EnvironmentCallbackFunction = Callable[[c_void_p], bool]
1212

13+
_ENVCALL_MEMBERS = EnvironmentCall.__members__.values()
14+
1315

1416
class DictEnvironmentDriver(
1517
EnvironmentDriver, Mapping[EnvironmentCall, EnvironmentCallbackFunction]
@@ -33,7 +35,7 @@ def __iter__(self) -> KeysView[EnvironmentCall]:
3335

3436
@override
3537
def environment(self, cmd: int, data: c_void_p) -> bool:
36-
if cmd not in EnvironmentCall:
38+
if cmd not in _ENVCALL_MEMBERS:
3739
return False
3840

3941
envcall = EnvironmentCall(cmd)

src/libretro/drivers/input/generator.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131

3232
from .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)
3644
class 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]

src/libretro/drivers/vfs/interface.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
retro_vfs_write_t,
3636
)
3737

38+
_VFS_SEEK_POSITION_MEMBERS = VfsSeekPosition.__members__.values()
39+
_VFS_MKDIR_RESULT_MEMBERS = VfsMkdirResult.__members__.values()
40+
3841

3942
@runtime_checkable
4043
class FileHandle(Protocol):
@@ -292,7 +295,7 @@ def __seek(self, stream: POINTER(retro_vfs_file_handle), offset: int, whence: in
292295
assert isinstance(offset, int)
293296
assert isinstance(whence, int)
294297

295-
if whence not in VfsSeekPosition:
298+
if whence not in _VFS_SEEK_POSITION_MEMBERS:
296299
return -1
297300

298301
try:
@@ -473,7 +476,7 @@ def __mkdir(self, path: bytes) -> int:
473476
try:
474477
ok = self.mkdir(path)
475478

476-
if ok not in VfsMkdirResult:
479+
if ok not in _VFS_MKDIR_RESULT_MEMBERS:
477480
raise TypeError(
478481
f"Expected mkdir to return a VfsMkdirResult, got: {type(ok).__name__}"
479482
)

src/libretro/drivers/video/opengl/moderngl.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from copy import deepcopy
66
from importlib import resources
77
from sys import modules
8-
from typing import final, override
8+
from typing import final
99

1010
import moderngl
1111

@@ -30,6 +30,7 @@
3030
)
3131
from OpenGL import GL
3232

33+
from libretro._typing import override
3334
from libretro.api.av import retro_game_geometry, retro_system_av_info
3435
from libretro.api.video import (
3536
HardwareContext,

0 commit comments

Comments
 (0)