Find the end of the class/func block starting at `start_index` in a source code (defined by `lines`). Args: lines (`List[str]`): The source code, represented by a list of lines. start_index (`int`): The starting index of the target class/func block.
(lines: list[str], start_index: int, indent: int)
| 258 | |
| 259 | |
| 260 | def find_block_end(lines: list[str], start_index: int, indent: int) -> int: |
| 261 | """ |
| 262 | Find the end of the class/func block starting at `start_index` in a source code (defined by `lines`). |
| 263 | |
| 264 | Args: |
| 265 | lines (`List[str]`): |
| 266 | The source code, represented by a list of lines. |
| 267 | start_index (`int`): |
| 268 | The starting index of the target class/func block. |
| 269 | indent (`int`): |
| 270 | The indent of the class/func body. |
| 271 | |
| 272 | Returns: |
| 273 | `int`: The index of the block's ending line plus by 1 (i.e. exclusive). |
| 274 | """ |
| 275 | indent = " " * indent |
| 276 | # enter the block body |
| 277 | line_index = start_index + 1 |
| 278 | |
| 279 | while line_index < len(lines) and _should_continue(lines[line_index], indent): |
| 280 | line_index += 1 |
| 281 | # Clean up empty lines at the end (if any). |
| 282 | while len(lines[line_index - 1]) <= 1: |
| 283 | line_index -= 1 |
| 284 | |
| 285 | return line_index |
| 286 | |
| 287 | |
| 288 | def split_code_into_blocks( |
no test coverage detected