Line range covering an entire method including decorators and a preceding COMMENT line.
(
func_node: ast.FunctionDef | ast.AsyncFunctionDef, lines: list[str]
)
| 387 | |
| 388 | |
| 389 | def _method_removal_range( |
| 390 | func_node: ast.FunctionDef | ast.AsyncFunctionDef, lines: list[str] |
| 391 | ) -> range: |
| 392 | """Line range covering an entire method including decorators and a preceding COMMENT line.""" |
| 393 | first = ( |
| 394 | func_node.decorator_list[0].lineno - 1 |
| 395 | if func_node.decorator_list |
| 396 | else func_node.lineno - 1 |
| 397 | ) |
| 398 | if ( |
| 399 | first > 0 |
| 400 | and lines[first - 1].strip().startswith("#") |
| 401 | and COMMENT in lines[first - 1] |
| 402 | ): |
| 403 | first -= 1 |
| 404 | # Also remove a preceding blank line to avoid double-blanks after removal |
| 405 | if first > 0 and not lines[first - 1].strip(): |
| 406 | first -= 1 |
| 407 | return range(first, func_node.end_lineno) |
| 408 | |
| 409 | |
| 410 | def _build_inheritance_info(tree: ast.Module) -> tuple[dict, dict]: |
no test coverage detected