Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita796939

Browse files
committed
updates stub file generator
1 parent5666220 commita796939

File tree

2 files changed

+151
-45
lines changed

2 files changed

+151
-45
lines changed

‎gen/python_api_gen_mpy.py‎

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,49 +1036,49 @@ class MissingConversionException(ValueError):
10361036
'va_list':'*args',
10371037
'void *':'Any',
10381038
'void *[]':'Any',
1039-
'char *[]':'List[Union[bytearray, bytes,str, List[int]]]',
1040-
'uint8_t *':'Union[bytearray, bytes, List[int]]',
1039+
'char *[]':'List[str]',
1040+
'uint8_t *':'Union[str, List[int]]',
10411041
'uint16_t *':'List[int]',
10421042
'uint32_t *':'List[int]',
10431043
'uint64_t *':'List[int]',
10441044
'int8_t *':'List[int]',
10451045
'int16_t *':'List[int]',
10461046
'int32_t *':'List[int]',
10471047
'int64_t *':'List[int]',
1048-
'const uint8_t *':'array.array',
1049-
'const uint16_t *':'array.array',
1050-
'const uint32_t *':'array.array',
1051-
'const uint64_t *':'array.array',
1052-
'const uint8_t **':'List[array.array]',
1053-
'const uint16_t **':'List[array.array]',
1054-
'const uint32_t **':'List[array.array]',
1055-
'const uint64_t **':'List[array.array]',
1056-
'const int8_t *':'array.array',
1057-
'const int16_t *':'array.array',
1058-
'const int32_t *':'array.array',
1059-
'const int64_t *':'array.array',
1060-
'const int8_t **':'List[array.array]',
1061-
'const int16_t **':'List[array.array]',
1062-
'const int32_t **':'List[array.array]',
1063-
'const int64_t **':'List[array.array]',
1048+
'const uint8_t *':'str',
1049+
'const uint16_t *':'List[int]',
1050+
'const uint32_t *':'List[int]',
1051+
'const uint64_t *':'List[int]',
1052+
'const uint8_t **':'List[bytes]',
1053+
'const uint16_t **':'List[List[int]]',
1054+
'const uint32_t **':'List[List[int]]',
1055+
'const uint64_t **':'List[List[int]]',
1056+
'const int8_t *':'List[int]',
1057+
'const int16_t *':'List[int]',
1058+
'const int32_t *':'List[int]',
1059+
'const int64_t *':'List[int]',
1060+
'const int8_t **':'List[List[int]]',
1061+
'const int16_t **':'List[List[int]]',
1062+
'const int32_t **':'List[List[int]]',
1063+
'const int64_t **':'List[List[int]]',
10641064
'const void *':'Any',
10651065
'bool':'bool',
1066-
'char *':'Union[str, bytearray, bytes, List[int]]',
1067-
'char **':'List[Union[str, bytearray, bytes, List[int]]]',
1068-
'const char *':'array.array',
1069-
'const char **':'List[array.array]',
1066+
'char *':'str',
1067+
'char **':'List[str]',
1068+
'const char *':'str',
1069+
'const char **':'List[str]',
10701070
'uint8_t':'int',
10711071
'uint16_t':'int',
10721072
'uint32_t':'int',
10731073
'uint64_t':'int',
10741074
'unsigned':'int',
10751075
'unsigned int':'int',
1076-
'unsigned char':'Union[int,str, bytearray, bytes]',
1077-
'const unsigned char':'Union[int, array.array]',
1078-
'unsigned char *':'Union[str, bytearray, bytes]',
1079-
'unsigned char **':'List[Union[str, bytearray, bytes]]',
1080-
'const unsigned char *':'array.array',
1081-
'const unsigned char **':'List[array.array]',
1076+
'unsigned char':'str',
1077+
'const unsigned char':'str',
1078+
'unsigned char *':'str',
1079+
'unsigned char **':'List[str]',
1080+
'const unsigned char *':'str',
1081+
'const unsigned char **':'List[str]',
10821082
'unsigned short':'int',
10831083
'unsigned long':'int',
10841084
'unsigned long int':'int',
@@ -1098,7 +1098,7 @@ class MissingConversionException(ValueError):
10981098
'int64_t':'int',
10991099
'size_t':'int',
11001100
'int':'int',
1101-
'char':'Union[int,str, bytes, bytearray]',
1101+
'char':'str',
11021102

11031103
'short':'int',
11041104
'long':'int',
@@ -1112,17 +1112,17 @@ class MissingConversionException(ValueError):
11121112
'const long long':'int',
11131113
'const long long int':'int',
11141114

1115-
'short *':'array.array',
1116-
'long *':'array.array',
1117-
'long int *':'array.array',
1118-
'long long *':'array.array',
1119-
'long long int *':'array.array',
1120-
1121-
'const short *':'array.array',
1122-
'const long *':'array.array',
1123-
'const long int *':'array.array',
1124-
'const long long *':'array.array',
1125-
'const long long int *':'array.array',
1115+
'short *':'List[int]',
1116+
'long *':'List[int]',
1117+
'long int *':'List[int]',
1118+
'long long *':'List[int]',
1119+
'long long int *':'List[int]',
1120+
1121+
'const short *':'List[int]',
1122+
'const long *':'List[int]',
1123+
'const long int *':'List[int]',
1124+
'const long long *':'List[int]',
1125+
'const long long int *':'List[int]',
11261126

11271127
'void':'None',
11281128
'float':'float',

‎gen/stub_gen.py‎

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,9 @@ class _{cls_name}_type(TypedDict, total=False):
153153
154154
class {cls_name}(object):
155155
"""
156-
Non Docstrings Yet
156+
No Docstrings Yet
157157
"""
158-
159-
def __init__(self, args: _{cls_name}_type) -> "{cls_name}":
158+
def __init__(self, args: Optional[_{cls_name}_type] = dict(), /) -> "{cls_name}":
160159
"""
161160
No Docstrings Yet
162161
"""
@@ -290,6 +289,47 @@ def build_struct(cls_name, struct):
290289
struct_output= []
291290

292291

292+
enum_types=set()
293+
294+
295+
defread_enums(objs):
296+
297+
def_iter_list(lst):
298+
foriteminlst:
299+
ifisinstance(item,dict):
300+
_iter_dict(item)
301+
elifisinstance(item,list):
302+
_iter_list(item)
303+
304+
def_iter_dict(d):
305+
306+
forkey,valueind.items():
307+
ifisinstance(value,dict):
308+
ifkey.lower()in (
309+
'anim','event','style','long','key','src','layout',
310+
'point_transform_flag','anim_image_part','log_level',
311+
'font_subpx','header','pinyin_mode','tree_walk',
312+
'class_theme_inheritable','subject_type','update_mode',
313+
'compress','class_group_def','symbol','scr_load_anim',
314+
'font_fmt_txt','coord','class_editable','part_textarea',
315+
'fs_seek','draw_task_state','layer_type','axis',
316+
'font_fmt_txt_cmap','draw_sw_mask_type','cell_ctrl',
317+
'cache_reserve_cond','root_back_button',
318+
):
319+
continue
320+
321+
if'c_type'invalueandvalue['c_type']=='enum':
322+
enum_types.add(key.lower()+'_t')
323+
elif'py_type'invalueandvalue['py_type']=='class'and'c_type'invalueandvalue['c_type'].isupper()and'members'invalue:
324+
enum_types.add(key.lower()+'_t')
325+
326+
_iter_dict(value)
327+
elifisinstance(value,list):
328+
_iter_list(value)
329+
330+
_iter_dict(objs)
331+
332+
293333
defbuild_objects(objects):
294334
forname,objinobjects.items():
295335
object_output.append(build_class(name,obj))
@@ -322,8 +362,71 @@ def build_structs(structs):
322362
struct_output.append(build_struct(name,struct))
323363

324364

365+
defbuild_enum_types():
366+
res= []
367+
fornameinenum_types:
368+
res.append(f'{name} = int')
369+
370+
return'\n'.join(res)
371+
372+
325373
output_template='''\
326-
from typing import Union, ClassVar, Callable, List, Any, TypedDict
374+
from typing import Union, ClassVar, Callable, List, Any, TypedDict, Optional
375+
376+
377+
{enum_types}
378+
style_prop_t = int
379+
grad_color_t = int
380+
event_code_t = int
381+
style_selector_t = int
382+
anim_enable_t = int
383+
event_list_t = int
384+
ll_node_t = int
385+
value_precise_t = float
386+
fs_whence_t = int
387+
screen_load_anim_t = int
388+
_mp_int_wrapper = int
389+
390+
event_cb_t = Callable
391+
group_edge_cb_t = Callable
392+
group_focus_cb_t = Callable
393+
indev_read_cb_t = Callable
394+
anim_exec_xcb_t = Callable
395+
cache_compare_cb_t = Callable
396+
rb_compare_t = Callable
397+
draw_buf_malloc_cb = Callable
398+
draw_buf_free_cb = Callable
399+
draw_buf_align_cb = Callable
400+
draw_buf_invalidate_cache_cb = Callable
401+
draw_buf_width_to_stride_cb = Callable
402+
draw_glyph_cb_t = Callable
403+
timer_handler_resume_cb_t = Callable
404+
delay_cb_t = Callable
405+
tick_get_cb_t = Callable
406+
407+
408+
class _draw_sw_mask_radius_circle_dsc_t(object):
409+
...
410+
411+
412+
class _draw_sw_mask_common_dsc_t(object):
413+
...
414+
415+
416+
class mutex_t(object):
417+
...
418+
419+
420+
class thread_sync_t(object):
421+
...
422+
423+
424+
class thread_t(object):
425+
...
426+
427+
428+
class mem_pool_t(object):
429+
...
327430
328431
329432
{constants}
@@ -347,6 +450,8 @@ def run(json_path):
347450

348451
root=json.loads(data)
349452

453+
read_enums(root)
454+
350455
build_objects(root['objects'])
351456
build_functions(root['functions'])
352457
if'enums'inroot:
@@ -363,7 +468,8 @@ def run(json_path):
363468
objects='\n'.join(object_output),
364469
variables='\n'.join(variable_output),
365470
funcs='\n\n'.join(func_output),
366-
structs=''.join(struct_output)
471+
structs=''.join(struct_output),
472+
enum_types=build_enum_types()
367473
)
368474

369475
withopen(OUPUT_FILE,'w')asf:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp