1
- import inspect
2
1
from typing import Any
3
2
3
+ from robotlibcore import KeywordBuilder # type: ignore
4
+
4
5
import Browser
5
6
6
7
@@ -40,40 +41,44 @@ def get_function_list_from_keywords(keywords):
40
41
method_name = get_method_name_for_keyword (keyword )
41
42
keyword_arguments = br .get_keyword_arguments (keyword )
42
43
keyword_types = br .get_keyword_types (keyword )
43
- arguments_list = list ()
44
- for argument in keyword_arguments :
45
- if isinstance (argument , tuple ):
46
- arg_str = argument [0 ]
47
- default_value = argument [1 ]
48
- arg_type_str = get_type_sting_from_argument (arg_str , keyword_types )
49
- if arg_type_str :
50
- if default_value is None :
51
- arg_type_str = f"Optional[{ arg_type_str } ]"
52
- if arg_type_str == "str" :
53
- default_value = f"'{ default_value } '"
54
- arg_str = arg_str + f": { arg_type_str } "
55
- elif isinstance (default_value , str ):
56
- default_value = f"'{ default_value } '"
57
- arg_str = arg_str + f" = { default_value } "
58
- else :
59
- arg_str = argument
60
- arg_type_str = get_type_sting_from_argument (arg_str , keyword_types )
61
- if arg_type_str :
62
- arg_str = arg_str + f": { arg_type_str } "
63
- arguments_list .append (arg_str )
64
- arguments_string = (
65
- f", { ', ' .join (arguments_list )} " if len (arguments_list ) > 0 else ""
66
- )
67
- functions .append (f" def { method_name } (self{ arguments_string } ): ...\n " )
44
+ functions .append (keyword_line (keyword_arguments , keyword_types , method_name ))
68
45
functions .sort ()
69
46
return functions
70
47
71
48
49
+ def keyword_line (keyword_arguments , keyword_types , method_name ):
50
+ arguments_list = list ()
51
+ for argument in keyword_arguments :
52
+ if isinstance (argument , tuple ):
53
+ arg_str = argument [0 ]
54
+ default_value = argument [1 ]
55
+ arg_type_str = get_type_sting_from_argument (arg_str , keyword_types )
56
+ if arg_type_str :
57
+ if default_value is None :
58
+ arg_type_str = f"Optional[{ arg_type_str } ]"
59
+ if arg_type_str == "str" :
60
+ default_value = f"'{ default_value } '"
61
+ arg_str = arg_str + f": { arg_type_str } "
62
+ elif isinstance (default_value , str ):
63
+ default_value = f"'{ default_value } '"
64
+ arg_str = arg_str + f" = { default_value } "
65
+ else :
66
+ arg_str = argument
67
+ arg_type_str = get_type_sting_from_argument (arg_str , keyword_types )
68
+ if arg_type_str :
69
+ arg_str = arg_str + f": { arg_type_str } "
70
+ arguments_list .append (arg_str )
71
+ arguments_string = (
72
+ f", { ', ' .join (arguments_list )} " if len (arguments_list ) > 0 else ""
73
+ )
74
+ return f" def { method_name } (self{ arguments_string } ): ...\n "
75
+
76
+
72
77
br : Any = Browser .Browser ()
73
78
function_list = get_function_list_from_keywords (br .get_keyword_names ())
74
79
75
80
76
- pyi_boilerplate = f """from concurrent.futures import Future
81
+ pyi_boilerplate = """from concurrent.futures import Future
77
82
from typing import (
78
83
Any,
79
84
Dict,
@@ -86,10 +91,14 @@ def get_function_list_from_keywords(keywords):
86
91
87
92
88
93
class Browser:
89
-
90
- def __init__(self, { str (inspect .signature (br .__init__ ))[1 :]} : ...\n
91
94
"""
92
95
96
+ init_method = KeywordBuilder .build (br .__init__ )
93
97
with open ("Browser/__init__.pyi" , "w" ) as stub_file :
94
98
stub_file .write (pyi_boilerplate )
99
+ stub_file .write (
100
+ keyword_line (
101
+ init_method .argument_specification , init_method .argument_types , "__init__"
102
+ )
103
+ )
95
104
stub_file .writelines (function_list )
0 commit comments