Skip to content

Commit e5fde1b

Browse files
committed
Improve typing.
1 parent fe02641 commit e5fde1b

File tree

8 files changed

+46
-58
lines changed

8 files changed

+46
-58
lines changed

sdl3/SDL_assert.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
SDL_ASSERTION_RETRY, SDL_ASSERTION_BREAK, SDL_ASSERTION_ABORT, \
1111
SDL_ASSERTION_IGNORE, SDL_ASSERTION_ALWAYS_IGNORE = range(5)
1212

13-
SDL_AssertData: typing.TypeAlias = SDL_TYPE["SDL_AssertData", ctypes.c_void_p]
14-
1513
class SDL_AssertData(ctypes.Structure):
1614
_fields_ = [
1715
("always_ignore", ctypes.c_bool),
@@ -20,7 +18,7 @@ class SDL_AssertData(ctypes.Structure):
2018
("filename", ctypes.c_char_p),
2119
("linenum", ctypes.c_int),
2220
("function", ctypes.c_char_p),
23-
("next", SDL_POINTER[SDL_AssertData])
21+
("next", SDL_POINTER[ctypes.c_void_p])
2422
]
2523

2624
SDL_ReportAssertion: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_ReportAssertion", SDL_AssertState, [SDL_POINTER[SDL_AssertData], ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int], SDL_BINARY]

sdl3/SDL_atomic.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ class SDL_AtomicInt(ctypes.Structure):
2121
SDL_GetAtomicInt: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_GetAtomicInt", ctypes.c_int, [SDL_POINTER[SDL_AtomicInt]], SDL_BINARY]
2222
SDL_AddAtomicInt: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_AddAtomicInt", ctypes.c_int, [SDL_POINTER[SDL_AtomicInt], ctypes.c_int], SDL_BINARY]
2323

24-
class LP_SDL_AtomicInt(ctypes._Pointer):
25-
...
26-
2724
SDL_AtomicIncRef: abc.Callable[[SDL_POINTER[SDL_AtomicInt]], ctypes.c_int] = lambda a: SDL_AddAtomicInt(a, 1)
2825
SDL_AtomicDecRef: abc.Callable[[SDL_POINTER[SDL_AtomicInt]], bool] = lambda a: SDL_AddAtomicInt(a, -1) == 1
2926

sdl3/SDL_audio.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
else:
3333
SDL_AUDIO_S16, SDL_AUDIO_S32, SDL_AUDIO_F32 = SDL_AUDIO_S16BE, SDL_AUDIO_S32BE, SDL_AUDIO_F32BE
3434

35-
SDL_AUDIO_BITSIZE: abc.Callable[[SDL_AudioFormat], int] = lambda x: x & SDL_AUDIO_MASK_BITSIZE
36-
SDL_AUDIO_BYTESIZE: abc.Callable[[SDL_AudioFormat], int] = lambda x: SDL_AUDIO_BITSIZE(x) / 8
35+
SDL_AUDIO_BITSIZE: abc.Callable[[SDL_AudioFormat], int] = lambda x: x.value & SDL_AUDIO_MASK_BITSIZE
36+
SDL_AUDIO_BYTESIZE: abc.Callable[[SDL_AudioFormat], int] = lambda x: int(SDL_AUDIO_BITSIZE(x) / 8)
3737

38-
SDL_AUDIO_ISFLOAT: abc.Callable[[SDL_AudioFormat], int] = lambda x: x & SDL_AUDIO_MASK_FLOAT
39-
SDL_AUDIO_ISBIGENDIAN: abc.Callable[[SDL_AudioFormat], int] = lambda x: x & SDL_AUDIO_MASK_BIG_ENDIAN
38+
SDL_AUDIO_ISFLOAT: abc.Callable[[SDL_AudioFormat], int] = lambda x: x.value & SDL_AUDIO_MASK_FLOAT
39+
SDL_AUDIO_ISBIGENDIAN: abc.Callable[[SDL_AudioFormat], int] = lambda x: x.value & SDL_AUDIO_MASK_BIG_ENDIAN
4040
SDL_AUDIO_ISLITTLEENDIAN: abc.Callable[[SDL_AudioFormat], bool] = lambda x: not SDL_AUDIO_ISBIGENDIAN(x)
41-
SDL_AUDIO_ISSIGNED: abc.Callable[[SDL_AudioFormat], int] = lambda x: x & SDL_AUDIO_MASK_SIGNED
41+
SDL_AUDIO_ISSIGNED: abc.Callable[[SDL_AudioFormat], int] = lambda x: x.value & SDL_AUDIO_MASK_SIGNED
4242
SDL_AUDIO_ISINT: abc.Callable[[SDL_AudioFormat], bool] = lambda x: not SDL_AUDIO_ISFLOAT(x)
4343
SDL_AUDIO_ISUNSIGNED: abc.Callable[[SDL_AudioFormat], bool] = lambda x: not SDL_AUDIO_ISSIGNED(x)
4444

sdl3/SDL_hidapi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class SDL_hid_device(ctypes.c_void_p):
1010
SDL_HID_API_BUS_UNKNOWN, SDL_HID_API_BUS_USB, SDL_HID_API_BUS_BLUETOOTH, \
1111
SDL_HID_API_BUS_I2C, SDL_HID_API_BUS_SPI = range(5)
1212

13-
SDL_hid_device_info: typing.TypeAlias = SDL_TYPE["SDL_hid_device_info", ctypes.c_void_p]
14-
1513
class SDL_hid_device_info(ctypes.Structure):
1614
_fields_ = [
1715
("path", ctypes.c_char_p),
@@ -28,7 +26,7 @@ class SDL_hid_device_info(ctypes.Structure):
2826
("interface_subclass", ctypes.c_int),
2927
("interface_protocol", ctypes.c_int),
3028
("bus_type", SDL_hid_bus_type),
31-
("next", SDL_POINTER[SDL_hid_device_info])
29+
("next", SDL_POINTER[ctypes.c_void_p])
3230
]
3331

3432
SDL_hid_init: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_hid_init", ctypes.c_int, [], SDL_BINARY]

sdl3/SDL_pixels.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@
3131
SDL_PACKEDLAYOUT_NONE, SDL_PACKEDLAYOUT_332, SDL_PACKEDLAYOUT_4444, SDL_PACKEDLAYOUT_1555, SDL_PACKEDLAYOUT_5551, SDL_PACKEDLAYOUT_565, \
3232
SDL_PACKEDLAYOUT_8888, SDL_PACKEDLAYOUT_2101010, SDL_PACKEDLAYOUT_1010102 = range(9)
3333

34+
SDL_DEFINE_PIXELFOURCC: abc.Callable[[str, str, str, str], int] = SDL_FOURCC
35+
3436
def SDL_DEFINE_PIXELFORMAT(ptype: int, order: int, layout: int, bits: int, pbytes: int) -> int:
3537
return (1 << 28) | (ptype << 24) | (order << 20) | (layout << 16) | (bits << 8) | (pbytes << 0)
3638

37-
SDL_DEFINE_PIXELFOURCC: abc.Callable[[int, int, int, int], int] = SDL_FOURCC
3839
SDL_ISPIXELFORMAT_FOURCC: abc.Callable[..., bool] = lambda format: format and SDL_PIXELFLAG(format) != 1
3940

40-
SDL_PIXELFLAG: abc.Callable[..., int] = lambda x: (x >> 28) & 0x0F
41-
SDL_PIXELTYPE: abc.Callable[..., int] = lambda x: (x >> 24) & 0x0F
42-
SDL_PIXELORDER: abc.Callable[..., int] = lambda x: (x >> 20) & 0x0F
43-
SDL_PIXELLAYOUT: abc.Callable[..., int] = lambda x: (x >> 16) & 0x0F
44-
SDL_BITSPERPIXEL: abc.Callable[..., int] = lambda x: (x >> 8) & 0xFF
41+
SDL_PIXELFLAG: abc.Callable[..., int] = lambda format: (format >> 28) & 0x0F
42+
SDL_PIXELTYPE: abc.Callable[..., int] = lambda format: (format >> 24) & 0x0F
43+
SDL_PIXELORDER: abc.Callable[..., int] = lambda format: (format >> 20) & 0x0F
44+
SDL_PIXELLAYOUT: abc.Callable[..., int] = lambda format: (format >> 16) & 0x0F
45+
SDL_BITSPERPIXEL: abc.Callable[..., int] = lambda format: 0 if SDL_ISPIXELFORMAT_FOURCC(format) else (format >> 8) & 0xFF
4546

46-
def SDL_BYTESPERPIXEL(x: int) -> int:
47-
if not SDL_ISPIXELFORMAT_FOURCC(x): return (x >> 0) & 0xFF
48-
else: return 2 if x in (SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_YVYU, SDL_PIXELFORMAT_P010) else 1
47+
def SDL_BYTESPERPIXEL(format: int) -> int:
48+
if not SDL_ISPIXELFORMAT_FOURCC(format): return (format >> 0) & 0xFF
49+
else: return 2 if format in [SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_YVYU, SDL_PIXELFORMAT_P010] else 1
4950

5051
def SDL_ISPIXELFORMAT_INDEXED(format: int) -> bool:
5152
return not SDL_ISPIXELFORMAT_FOURCC(format) and (SDL_PIXELTYPE(format) in [SDL_PIXELTYPE_INDEX1, SDL_PIXELTYPE_INDEX2, SDL_PIXELTYPE_INDEX4, SDL_PIXELTYPE_INDEX8])

sdl3/SDL_rect.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,19 @@ class SDL_FRect(ctypes.Structure):
3131
("h", ctypes.c_float)
3232
]
3333

34-
LP_SDL_Point: typing.TypeAlias = SDL_POINTER[SDL_Point]
35-
LP_SDL_FPoint: typing.TypeAlias = SDL_POINTER[SDL_FPoint]
36-
LP_SDL_Rect: typing.TypeAlias = SDL_POINTER[SDL_Rect]
37-
LP_SDL_FRect: typing.TypeAlias = SDL_POINTER[SDL_FRect]
38-
39-
def SDL_RectToFRect(rect: LP_SDL_Rect, frect: LP_SDL_FRect) -> None:
34+
def SDL_RectToFRect(rect: SDL_Rect, frect: SDL_FRect) -> None:
4035
rect, frect = SDL_DEREFERENCE(rect), SDL_DEREFERENCE(frect)
4136
frect.x, frect.y, frect.w, frect.h = float(rect.x), float(rect.y), float(rect.w), float(rect.h)
4237

43-
def SDL_PointInRect(p: LP_SDL_Point, r: LP_SDL_Rect) -> bool:
38+
def SDL_PointInRect(p: SDL_Point, r: SDL_Rect) -> bool:
4439
p, r = SDL_DEREFERENCE(p), SDL_DEREFERENCE(r)
4540
return p.x >= r.x and p.x < r.x + r.w and p.y >= r.y and p.y < r.y + r.h
4641

47-
def SDL_RectEmpty(r: LP_SDL_Rect) -> bool:
42+
def SDL_RectEmpty(r: SDL_Rect) -> bool:
4843
r = SDL_DEREFERENCE(r)
4944
return r.w <= 0 or r.h <= 0
5045

51-
def SDL_RectEquals(a: LP_SDL_Rect, b: LP_SDL_Rect) -> bool:
46+
def SDL_RectEquals(a: SDL_Rect, b: SDL_Rect) -> bool:
5247
a, b = SDL_DEREFERENCE(a), SDL_DEREFERENCE(b)
5348
return a.x == b.x and a.y == b.y and a.w == b.w and a.h == b.h
5449

@@ -58,20 +53,19 @@ def SDL_RectEquals(a: LP_SDL_Rect, b: LP_SDL_Rect) -> bool:
5853
SDL_GetRectEnclosingPoints: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_GetRectEnclosingPoints", ctypes.c_bool, [SDL_POINTER[SDL_Point], ctypes.c_int, SDL_POINTER[SDL_Rect], SDL_POINTER[SDL_Rect]], SDL_BINARY]
5954
SDL_GetRectAndLineIntersection: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_GetRectAndLineIntersection", ctypes.c_bool, [SDL_POINTER[SDL_Rect], SDL_POINTER[ctypes.c_int], SDL_POINTER[ctypes.c_int], SDL_POINTER[ctypes.c_int], SDL_POINTER[ctypes.c_int]], SDL_BINARY]
6055

61-
def SDL_PointInRectFloat(p: LP_SDL_FPoint, r: LP_SDL_FRect) -> bool:
56+
def SDL_PointInRectFloat(p: SDL_FPoint, r: SDL_FRect) -> bool:
6257
p, r = SDL_DEREFERENCE(p), SDL_DEREFERENCE(r)
6358
return p.x >= r.x and p.x < r.x + r.w and p.y >= r.y and p.y < r.y + r.h
6459

65-
def SDL_RectEmptyFloat(r: LP_SDL_FRect) -> bool:
60+
def SDL_RectEmptyFloat(r: SDL_FRect) -> bool:
6661
r = SDL_DEREFERENCE(r)
6762
return r.w <= 0 or r.h <= 0
6863

69-
def SDL_RectsEqualEpsilon(a: LP_SDL_FRect, b: LP_SDL_FRect, epsilon: float) -> bool:
64+
def SDL_RectsEqualEpsilon(a: SDL_FRect, b: SDL_FRect, epsilon: float) -> bool:
7065
a, b = SDL_DEREFERENCE(a), SDL_DEREFERENCE(b)
7166
return abs(a.x - b.x) < epsilon and abs(a.y - b.y) < epsilon and abs(a.w - b.w) < epsilon and abs(a.h - b.h) < epsilon
7267

73-
def SDL_RectsEqualFloat(a: LP_SDL_FRect, b: LP_SDL_FRect) -> bool:
74-
a, b = SDL_DEREFERENCE(a), SDL_DEREFERENCE(b)
68+
def SDL_RectsEqualFloat(a: SDL_FRect, b: SDL_FRect) -> bool:
7569
return SDL_RectsEqualEpsilon(a, b, SDL_FLT_EPSILON)
7670

7771
SDL_HasRectIntersectionFloat: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_HasRectIntersectionFloat", ctypes.c_bool, [SDL_POINTER[SDL_FRect], SDL_POINTER[SDL_FRect]], SDL_BINARY]

sdl3/SDL_stdinc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
SDL_arraysize: abc.Callable[[typing.Any], int] = lambda array: \
66
ctypes.sizeof(array) // ctypes.sizeof(array[0])
77

8-
def SDL_FOURCC(a: int, b: int, c: int, d: int) -> int:
8+
def SDL_FOURCC(a: str, b: str, c: str, d: str) -> int:
99
return (ord(a) << 0) | (ord(b) << 8) | (ord(c) << 16) | (ord(d) << 24)
1010

1111
Sint8: typing.TypeAlias = SDL_TYPE["Sint8", ctypes.c_int8]
@@ -122,7 +122,7 @@ class SDL_Environment(ctypes.c_void_p):
122122
SDL_memset4: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_memset4", ctypes.c_void_p, [ctypes.c_void_p, ctypes.c_uint32, ctypes.c_size_t], SDL_BINARY]
123123

124124
SDL_zero: abc.Callable[[ctypes.c_void_p], ctypes.c_void_p] = lambda x: SDL_memset(ctypes.byref(x), 0, ctypes.sizeof(x))
125-
SDL_zerop: abc.Callable[[ctypes.c_void_p], ctypes.c_void_p] = lambda x: SDL_memset(x, 0, ctypes.sizeof(x.contents))
125+
SDL_zerop: abc.Callable[[ctypes.c_void_p], ctypes.c_void_p] = lambda x: SDL_memset(x, 0, ctypes.sizeof(SDL_DEREFERENCE(x)))
126126
SDL_zeroa: abc.Callable[[ctypes.c_void_p], ctypes.c_void_p] = lambda x: SDL_memset(x, 0, ctypes.sizeof(x))
127127

128128
SDL_memcmp: abc.Callable[..., typing.Any] = SDL_FUNC["SDL_memcmp", ctypes.c_int, [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t], SDL_BINARY]

sdl3/__init__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,9 @@ def SDL_CHECK_BINARY_NAME(name: str) -> bool:
223223
if (name.split(".")[0] if "." in name else name).endswith(_name):
224224
binaryMap[module] = ctypes.CDLL(os.path.abspath(path))
225225

226-
BaseType = typing.TypeVar("BaseType")
227-
TargetType = typing.TypeVar("TargetType")
228-
229-
def SDL_ARRAY(*args: BaseType, **kwargs: TargetType) -> tuple[ctypes.Array[BaseType | TargetType], int]:
226+
def SDL_ARRAY(*values, type: typing.Any | None = None) -> tuple[typing.Any, int]:
230227
"""Create a ctypes array from the given arguments."""
231-
return ((kwargs.get("type", None) or args[0].__class__) * len(args))(*args), len(args)
228+
return ((type or values[0].__class__) * len(values))(*values), len(values)
232229

233230
def SDL_DEREFERENCE(value: typing.Any) -> typing.Any:
234231
"""Dereference a ctypes pointer or object."""
@@ -270,7 +267,7 @@ def __class_getitem__(cls, key: tuple[str, type, list[type], str]) -> typing.Any
270267
assert isinstance(key[0], str), "Expected a string as the first argument."
271268
assert isinstance(key[1], type) or key[1] is None, "Expected a type as the second argument."
272269
assert isinstance(key[2], list), "Expected a list as the third argument."
273-
assert ... not in key[2] or key[2].count(...) == 1, "Expected at most 1 '...' in the argument list."
270+
assert ... not in key[2] or key[2].count(...) == 1, "Expected at most 1 '...' in the argument list." # type: ignore
274271
assert ... not in key[2] or key[2][-1] == ..., "Expected '...' at the end of the argument list."
275272
assert isinstance(key[3], str), "Expected a string as the fourth argument."
276273
assert key[3] in SDL_MODULES, "Unknown binary."
@@ -358,16 +355,16 @@ def __class_getitem__(cls, key: tuple[str, type, list[type]]) -> type:
358355
assert isinstance(key[1], type) or key[1] is None, "Expected a type as the second argument."
359356
assert isinstance(key[2], list), "Expected a list as the third argument."
360357

361-
_, ctypes._c_functype_cache = ctypes._c_functype_cache, {}
358+
_, ctypes._c_functype_cache = ctypes._c_functype_cache, {} # type: ignore
362359
value = ctypes.CFUNCTYPE(key[1], *key[2])
363-
value.__name__, ctypes._c_functype_cache = key[0], _
360+
value.__name__, ctypes._c_functype_cache = key[0], _ # type: ignore
364361
return value
365362

366363
SDL_ENUM: typing.TypeAlias = SDL_TYPE["SDL_ENUM", ctypes.c_int]
367364
SDL_VA_LIST: typing.TypeAlias = SDL_TYPE["SDL_VA_LIST", ctypes.c_char_p]
368365

369366
def SDL_PARSE_ARGUMENTS(argc: ctypes.c_int, argv: SDL_POINTER[ctypes.c_char_p]) -> list[str]:
370-
return [argv[i].decode("utf-8") for i in range(argc)]
367+
return [argv[i].decode("utf-8") for i in range(argc.value)] # type: ignore
371368

372369
def SDL_PROCESS_DESCRIPTION(description: str, url: str | None = None, rst: bool = False) -> str:
373370
"""Process HTML description."""
@@ -410,7 +407,7 @@ async def SDL_GET_LATEST_RELEASES() -> dict[str, str]:
410407
await session.close()
411408
return releases
412409

413-
async def SDL_GET_FUNC_DESCRIPTIONS(funcs: list[tuple[str, str]], rst: bool = False) -> tuple[list[str], list[list[str]]]:
410+
async def SDL_GET_FUNC_DESCRIPTIONS(funcs: list[tuple[str, str]], rst: bool = False) -> tuple[list[str], list[list[str]], list[str]]:
414411
"""Get descriptions, arguments and return types of SDL3 functions from the official SDL3 wiki."""
415412
session, tasks = aiohttp.ClientSession(), []
416413

@@ -458,7 +455,7 @@ async def SDL_GET_FUNC_DESCRIPTIONS(funcs: list[tuple[str, str]], rst: bool = Fa
458455
await session.close()
459456
return descriptions, arguments, returns
460457

461-
async def SDL_GET_STRUCT_DESCRIPTIONS(structs: list[tuple[str, str]], rst: bool = False) -> tuple[list[str], list[list[str]]]:
458+
async def SDL_GET_STRUCT_DESCRIPTIONS(structs: list[tuple[str, str]], rst: bool = False) -> tuple[list[str], list[dict[str, typing.Any]]]:
462459
"""Get descriptions and members of SDL3 structures from the official SDL3 wiki."""
463460
session, tasks = aiohttp.ClientSession(), []
464461

@@ -518,7 +515,7 @@ async def SDL_GET_STRUCT_DESCRIPTIONS(structs: list[tuple[str, str]], rst: bool
518515
await session.close()
519516
return descriptions, members
520517

521-
def SDL_GET_MODULE_BY_NAME(name: str) -> str:
518+
def SDL_GET_MODULE_BY_NAME(name: str) -> str | None:
522519
"""Get the module of an SDL3 function/structure by its name."""
523520

524521
for prefix, module in sorted({"SDL": "SDL3", "IMG": "SDL3_image", "Mix": "SDL3_mixer", "TTF": "SDL3_ttf", "RTF": "SDL3_rtf", "NET": "SDL3_net", "SDL_ShaderCross": "SDL3_shadercross"}.items(), key = lambda x: -len(x[0])):
@@ -565,11 +562,13 @@ def SDL_GENERATE_DOCS(modules: list[str] = SDL_MODULES, raw: types.ModuleType |
565562
if (_ := __module__.functions[module][func]).__name__ == "__inner__": _ = _.func
566563
_.__doc__ = (descriptions[__index := __index + 1], arguments[__index], returns[__index])
567564

565+
structs = False
568566
result = "" if rst else "\"\"\"\n# This file is auto-generated, do not modify it.\n__meta__ = "
569567
if not rst: result += f"{{\"target\": \"v{__version__}\", \"system\": \"{SDL_SYSTEM}\"}}\n\"\"\"\n\n"
570-
result += f"from {'sdl3' if rst else ''}.SDL import * # type: ignore\n\n"
571-
result += f"from {'sdl3' if rst else ''}. import {'' if rst else 'raw, '}ctypes, typing, {'SDL_POINTER' if rst else ''}"
572-
result += "\n" if rst else f"\\\n{' ' * 4}SDL_POINTER, SDL_CLONE_METACLASS as SDL_CloneMeta\n\n"
568+
result += f"from {'sdl3' if rst else ''}.SDL import * # type: ignore\n"
569+
result += f"from {'sdl3' if rst else '.'} import {'' if rst else 'raw, '}SDL_POINTER"
570+
result += "\n\n" if rst or not structs else f", \\\n{' ' * 4}SDL_CLONE_METACLASS as SDL_CloneMeta\n\n"
571+
result += "import ctypes, typing\n\n"
573572
types, definitions = set(), ""
574573

575574
def SDL_GET_FULL_NAME(type: type | None) -> str:
@@ -578,9 +577,9 @@ def SDL_GET_FULL_NAME(type: type | None) -> str:
578577
if type.__name__.startswith("c_"): return f"ctypes.{type.__name__}"
579578
else: return type.__name__
580579

581-
if not rst and raw is not None:
582-
structs = [(SDL_GET_MODULE_BY_NAME(name), name) for name in dir(raw) if hasattr(getattr(raw, name), "_fields_") \
583-
and not name.startswith("_") and "_" in name and name not in ["SDL_GamepadBinding", "SDL_TLSID"]]
580+
if not rst and raw is not None and structs:
581+
structs = [(module, name) for name in dir(raw) if hasattr(getattr(raw, name), "_fields_") and not name.startswith("_") \
582+
and "_" in name and name not in ["SDL_GamepadBinding", "SDL_TLSID"] and (module := SDL_GET_MODULE_BY_NAME(name))]
584583

585584
for (module, name), description, members in zip(structs, *asyncio.run(SDL_GET_STRUCT_DESCRIPTIONS(structs))):
586585
if not description or not members:
@@ -748,7 +747,8 @@ def SDL_TRY_WRITE_DOCS() -> bool | None:
748747
else:
749748
try:
750749
if not (__frozen__ or __release__):
751-
if os.path.exists(__doc_file__): os.remove(__doc_file__)
750+
if os.path.exists(__doc_file__):
751+
os.remove(__doc_file__)
752752

753753
except PermissionError as exc:
754754
SDL_LOGGER.Log(SDL_LOGGER.Error, f"Failed to remove docs: {exc}.")

0 commit comments

Comments
 (0)