@@ -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
233230def 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
366363SDL_ENUM : typing .TypeAlias = SDL_TYPE ["SDL_ENUM" , ctypes .c_int ]
367364SDL_VA_LIST : typing .TypeAlias = SDL_TYPE ["SDL_VA_LIST" , ctypes .c_char_p ]
368365
369366def 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
372369def 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