@@ -1169,6 +1169,13 @@ def return_val_exists_in_func(module_str, func_name):
11691169 func_str = func_str , module_str = module_str , func_name = func_name )
11701170 if func_str == '' :
11711171 return False
1172+ func_indent_num = get_func_indent_num (
1173+ py_module_str = module_str ,
1174+ func_name = func_name )
1175+ func_str = _remove_nested_func_str (
1176+ func_str = func_str , func_indent_num = func_indent_num )
1177+ if func_str == '' :
1178+ return False
11721179 line_splitted_list = func_str .split ('\n ' )
11731180 for line_str in line_splitted_list :
11741181 return_statement_exists = 'return' in line_str
@@ -1183,6 +1190,79 @@ def return_val_exists_in_func(module_str, func_name):
11831190 return False
11841191
11851192
1193+ def _add_line_str (target_str , line_str ):
1194+ """
1195+ Add target line string for string concatenation.
1196+
1197+ Parameters
1198+ ----------
1199+ target_str : str
1200+ The string to be concatenated.
1201+ line_str : str
1202+ String of target line.
1203+
1204+ Returns
1205+ -------
1206+ target_str : str
1207+ Concatenated string.
1208+ """
1209+
1210+ if target_str != '' :
1211+ target_str += '\n '
1212+ target_str += line_str
1213+ return target_str
1214+
1215+
1216+ def _remove_nested_func_str (func_str , func_indent_num ):
1217+ """
1218+ Remove the string of nested function part.
1219+
1220+ Parameters
1221+ ----------
1222+ func_str : str
1223+ Target function string.
1224+ func_indent_num : int
1225+ Indent number of the target function (starting from 1).
1226+
1227+ Returns
1228+ -------
1229+ removed_func_str : str
1230+ The string after removed nested function part.
1231+ """
1232+
1233+ removed_func_str = ''
1234+ line_splitted_list = func_str .split ('\n ' )
1235+ is_initial_function_appeared = False
1236+ is_nested_func_line = False
1237+ for line_str in line_splitted_list :
1238+ is_func_statement_in = 'def ' in line_str
1239+ if not is_nested_func_line :
1240+ if not is_func_statement_in or not is_initial_function_appeared :
1241+ removed_func_str = _add_line_str (
1242+ target_str = removed_func_str , line_str = line_str )
1243+ if not is_initial_function_appeared and is_func_statement_in :
1244+ is_initial_function_appeared = True
1245+ continue
1246+ if not is_initial_function_appeared :
1247+ continue
1248+ line_indent_num = get_line_indent_num (line_str = line_str )
1249+ if is_nested_func_line :
1250+ if line_str .strip () == '' or '):' in line_str :
1251+ continue
1252+ if (line_indent_num <= func_indent_num
1253+ and not is_func_statement_in ):
1254+ is_nested_func_line = False
1255+ removed_func_str = _add_line_str (
1256+ target_str = removed_func_str , line_str = line_str )
1257+ continue
1258+ if is_func_statement_in and not is_nested_func_line :
1259+ if line_indent_num < func_indent_num :
1260+ continue
1261+ is_nested_func_line = True
1262+ continue
1263+ return removed_func_str
1264+
1265+
11861266def _remove_docstring_from_func_str (func_str , module_str , func_name ):
11871267 """
11881268 Remove the doctring from the function string.
0 commit comments