@@ -237,6 +237,48 @@ def _extract_task_class_info(self, task_name: str) -> Dict[str, Any]:
237237
238238 return class_info
239239
240+ def _clean_init_method (self , init_method : str ) -> str :
241+ """
242+ Clean up extracted __init__ method body by removing docstrings and super() calls.
243+ Keep only the actual initialization statements.
244+ """
245+ lines = init_method .split ('\n ' )
246+ cleaned_lines = []
247+ in_docstring = False
248+
249+ for line in lines :
250+ stripped = line .strip ()
251+
252+ # Skip docstring lines
253+ if '"""' in line :
254+ if in_docstring :
255+ in_docstring = False
256+ continue
257+ else :
258+ in_docstring = True
259+ continue
260+
261+ if in_docstring :
262+ continue
263+
264+ # Skip super() calls
265+ if 'super().__init__' in line or 'super().__init__' in line :
266+ continue
267+
268+ # Skip empty lines
269+ if not stripped :
270+ continue
271+
272+ # Keep actual initialization statements (assignments to self.*)
273+ if stripped .startswith ('self.' ) or '=' in stripped :
274+ # Ensure proper indentation (8 spaces for method body)
275+ cleaned_lines .append (' ' + stripped )
276+
277+ if cleaned_lines :
278+ return '\n ' .join (cleaned_lines )
279+ else :
280+ return ' pass'
281+
240282 def _generate_initial_program (self , task_name : str ) -> str :
241283 """Generate the initial program for OpenEvolve based on the actual task implementation."""
242284 task_info = self .available_tasks [task_name ]
@@ -298,8 +340,8 @@ def _generate_initial_program(self, task_name: str) -> str:
298340 # Use the actual __init__ method from the original task
299341 init_method = class_info ['init_method' ]
300342 if init_method :
301- # The method body is already properly indented from extraction
302- init_method_body = init_method
343+ # Clean up the extracted __init__ method
344+ init_method_body = self . _clean_init_method ( init_method )
303345 else :
304346 # Fallback to simple pass if extraction failed
305347 init_method_body = ' pass'
0 commit comments