dedent before ast.parse for non-toplevel functions

This commit is contained in:
robrobo
2025-06-17 01:02:15 +02:00
parent 6d8b86c1ef
commit 7585e598dc

View File

@ -8,6 +8,7 @@ import ast
import io import io
import tokenize import tokenize
import re import re
import textwrap
import numpy as np import numpy as np
@ -45,7 +46,7 @@ def strip_comments(source: str) -> str:
for child in ast.iter_child_nodes(node): for child in ast.iter_child_nodes(node):
remove_docstrings(child) remove_docstrings(child)
tree = ast.parse(source) tree = ast.parse(textwrap.dedent(source))
remove_docstrings(tree) remove_docstrings(tree)
code_without_docstrings = ast.unparse(tree) code_without_docstrings = ast.unparse(tree)