add doc strings and fake classes to the type hints
This commit is contained in:
parent
3044797382
commit
13ca8d2ae8
2 changed files with 2623 additions and 535 deletions
|
@ -1,8 +1,7 @@
|
|||
from raylib.static import rl, ffi
|
||||
|
||||
from inspect import ismethod,getmembers,isbuiltin
|
||||
import inflection
|
||||
|
||||
from inspect import ismethod, getmembers, isbuiltin
|
||||
import inflection, sys
|
||||
|
||||
print("""from typing import Any
|
||||
|
||||
|
@ -23,36 +22,61 @@ def ctype_to_python_type(t):
|
|||
return "float"
|
||||
elif "char *" in t:
|
||||
return "str"
|
||||
elif "char" in t:
|
||||
return "str" # not sure about this one
|
||||
elif "*" in t:
|
||||
return "Any"
|
||||
elif t.startswith("struct"):
|
||||
return "Any" # This should be CData but cant get PyCharm to understand that - it just shows up as None
|
||||
return t.replace("struct ","")
|
||||
elif t.startswith("unsigned"):
|
||||
return t.replace("unsigned ","")
|
||||
return t.replace("unsigned ", "")
|
||||
else:
|
||||
return t
|
||||
|
||||
|
||||
for name, attr in getmembers(rl):
|
||||
uname = inflection.underscore(name).replace('3_d', '_3d').replace('2_d', '_2d')
|
||||
if isbuiltin(attr) or str(type(attr)) == "<class '_cffi_backend.__FFIFunctionWrapper'>":
|
||||
|
||||
|
||||
sig = ""
|
||||
for i, arg in enumerate(ffi.typeof(attr).args):
|
||||
param_name = arg.cname.replace("struct","").replace("char *","str").replace("*","_pointer").replace(" ","")
|
||||
param_name = arg.cname.replace("struct", "").replace("char *", "str").replace("*",
|
||||
"_pointer").replace(
|
||||
" ", "")
|
||||
param_type = ctype_to_python_type(arg.cname)
|
||||
sig += f", {param_name}_{i}: {param_type}"
|
||||
|
||||
|
||||
return_type = ffi.typeof(attr).result.cname
|
||||
|
||||
print(
|
||||
f' def {uname}(self{sig}) -> {ctype_to_python_type(return_type)}:\n """{attr.__doc__}"""\n ...')
|
||||
|
||||
print(f" def {uname}(self{sig}) -> {ctype_to_python_type(return_type)}: ...")
|
||||
|
||||
|
||||
elif str(type(attr)) == "<class '_cffi_backend._CDataBase'>":
|
||||
return_type = ffi.typeof(attr).result.cname
|
||||
print(
|
||||
f' def {uname}(self, *args) -> {ctype_to_python_type(return_type)}:\n """VARARG FUNCTION - MAY NOT BE SUPPORTED BY CFFI"""\n ...')
|
||||
else:
|
||||
print(f" {name}: {str(type(attr))[8:-2]}") # this isolates the type
|
||||
|
||||
#print("*****", str(type(attr)))
|
||||
print(f" {name}: {str(type(attr))[8:-2]}") # this isolates the type
|
||||
|
||||
for struct in ffi.list_types()[0]:
|
||||
print(f" {struct}: Any") # This should be CData but cant get PyCharm to understand that - it just shows up as None
|
||||
print("processing", struct, file=sys.stderr)
|
||||
if ffi.typeof(struct).kind == "struct":
|
||||
if ffi.typeof(struct).fields is None:
|
||||
print("weird empty struct, skipping", file=sys.stderr)
|
||||
break
|
||||
print(f" class {struct}:")
|
||||
sig = ""
|
||||
for arg in ffi.typeof(struct).fields:
|
||||
sig += ", " + arg[0]
|
||||
print(f" def __init__(self{sig}):")
|
||||
|
||||
for arg in ffi.typeof(struct).fields:
|
||||
print(f" self.{arg[0]}={arg[0]}")
|
||||
|
||||
elif ffi.typeof(struct).kind == "enum":
|
||||
print(f" {struct}: int")
|
||||
else:
|
||||
print("ERROR UNKNOWN TYPE", ffi.typeof(struct), file=sys.stderr)
|
||||
|
||||
|
||||
|
|
3106
raylib/pyray.pyi
3106
raylib/pyray.pyi
File diff suppressed because it is too large
Load diff
Reference in a new issue