@@ -74,6 +74,20 @@ def _create_func_problem_test(self, dir_loc, p: Problem):
74
74
tmp = input_param .split (": " )
75
75
input_type = tmp [1 ]
76
76
# remove Optional
77
+ while "Optional[" in input_type :
78
+ beg_idx = input_type .find ("Optional[" )
79
+ score = 0
80
+ end_idx = - 1
81
+ for i in range (beg_idx , len (input_type )):
82
+ if input_type [i ] == "[" :
83
+ score += 1
84
+ elif input_type [i ] == "]" :
85
+ score -= 1
86
+ if score == 0 :
87
+ end_idx = i
88
+ break
89
+ input_type = input_type [:beg_idx ] + input_type [beg_idx + 9 :end_idx ] + input_type [end_idx + 1 :]
90
+
77
91
if input_type .startswith ("Optional[" ):
78
92
input_type = input_type [9 :- 1 ]
79
93
input_name = tmp [0 ]
@@ -82,8 +96,21 @@ def _create_func_problem_test(self, dir_loc, p: Problem):
82
96
f"{ input_name } : { input_type } = convert_params(data[i * one_test_number + { idx } ], '{ input_type } ')" )
83
97
input_names .append (input_name )
84
98
85
- if f .output_params .startswith ("Optional[" ):
86
- f .output_params = f .output_params [9 :- 1 ]
99
+ while "Optional[" in f .output_params :
100
+ beg_idx = f .output_params .find ("Optional[" )
101
+ score = 0
102
+ end_idx = - 1
103
+ for i in range (beg_idx , len (f .output_params )):
104
+ if f .output_params [i ] == "[" :
105
+ score += 1
106
+ elif f .output_params [i ] == "]" :
107
+ score -= 1
108
+ if score == 0 :
109
+ end_idx = i
110
+ break
111
+ f .output_params = f .output_params [:beg_idx ] + f .output_params [beg_idx + 9 :end_idx ] + f .output_params [
112
+ end_idx + 1 :]
113
+
87
114
build_params_str_list .append (
88
115
f"real_res: { f .output_params } = convert_params(data[i * one_test_number + { input_number } ], '{ f .output_params } ')" )
89
116
build_params_str_list = [self ._generate_code_with_indent (s , 2 ) for s in build_params_str_list ]
0 commit comments