Return the FIRST docstring found in the HumanEval prompt code. We use `ast` so multi-line strings inside the function are handled correctly. Return empty string if parsing fails or no docstring is found.
(prompt: str)
| 121 | |
| 122 | |
| 123 | def _module_docstring(prompt: str) -> str: |
| 124 | """Return the FIRST docstring found in the HumanEval prompt code. |
| 125 | |
| 126 | We use `ast` so multi-line strings inside the function are handled |
| 127 | correctly. Return empty string if parsing fails or no docstring is found. |
| 128 | """ |
| 129 | try: |
| 130 | tree = ast.parse(prompt) |
| 131 | except SyntaxError: |
| 132 | return "" |
| 133 | for node in ast.walk(tree): |
| 134 | if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.Module)): |
| 135 | doc = ast.get_docstring(node) |
| 136 | if doc: |
| 137 | return doc |
| 138 | return "" |
| 139 | |
| 140 | |
| 141 | def _normalize_expected_repr(raw: str, entry_point: str) -> str: |
no test coverage detected