@@ -613,7 +613,7 @@ def prune_cst_for_code_hashing( # noqa: PLR0911
613613 if isinstance (node , cst .FunctionDef ):
614614 qualified_name = f"{ prefix } .{ node .name .value } " if prefix else node .name .value
615615 if qualified_name in target_functions :
616- new_body = remove_docstring_from_body (node .body )
616+ new_body = remove_docstring_from_body (node .body ) if isinstance ( node . body , cst . IndentedBlock ) else node . body
617617 return node .with_changes (body = new_body ), True
618618 return None , False
619619
@@ -632,14 +632,13 @@ def prune_cst_for_code_hashing( # noqa: PLR0911
632632 if isinstance (stmt , cst .FunctionDef ):
633633 qualified_name = f"{ class_prefix } .{ stmt .name .value } "
634634 if qualified_name in target_functions :
635- new_body .append (stmt )
635+ stmt_with_changes = stmt .with_changes (body = remove_docstring_from_body (stmt .body ))
636+ new_body .append (stmt_with_changes )
636637 found_target = True
637638 # If no target functions found, remove the class entirely
638639 if not new_body or not found_target :
639640 return None , False
640- return node .with_changes (
641- body = remove_docstring_from_body (node .body .with_changes (body = new_body ))
642- ) if new_body else None , True
641+ return node .with_changes (body = cst .IndentedBlock (new_body )) if new_body else None , found_target
643642
644643 # For other nodes, we preserve them only if they contain target functions in their children.
645644 section_names = get_section_names (node )
0 commit comments