(node: cst.Module)
| 535 | |
| 536 | @staticmethod |
| 537 | def add_future_import(node: cst.Module) -> cst.Module: |
| 538 | stmts = list(node.body) |
| 539 | first_stmt = stmts[0] if stmts else None |
| 540 | if not ( |
| 541 | first_stmt |
| 542 | and isinstance(first_stmt, cst.SimpleStatementLine) |
| 543 | and isinstance(first_stmt.body[0], cst.ImportFrom) |
| 544 | and isinstance(first_stmt.body[0].module, cst.Name) |
| 545 | and first_stmt.body[0].module.value == "__future__" |
| 546 | and first_stmt.body[0].names |
| 547 | and isinstance(first_stmt.body[0].names[0], cst.ImportAlias) |
| 548 | and isinstance(first_stmt.body[0].names[0].name, cst.Name) |
| 549 | and first_stmt.body[0].names[0].name.value == "annotations" |
| 550 | ): |
| 551 | import_stmt = cst.SimpleStatementLine( |
| 552 | [cst.ImportFrom(cst.Name("__future__"), [cst.ImportAlias(cst.Name("annotations"))])] |
| 553 | ) |
| 554 | if ( |
| 555 | isinstance(first_stmt, cst.SimpleStatementLine) |
| 556 | and isinstance(first_stmt.body[0], (cst.Import, cst.ImportFrom)) |
| 557 | and not first_stmt.leading_lines |
| 558 | ): |
| 559 | first_stmt = first_stmt.with_changes(leading_lines=[cst.EmptyLine()]) |
| 560 | stmts = [first_stmt] + stmts[1:] |
| 561 | |
| 562 | node = node.with_changes(body=[import_stmt] + stmts) |
| 563 | |
| 564 | return node |
| 565 | |
| 566 | |
| 567 | class IndexPythonClassesVisitor(CstVisitorBase): |
no outgoing calls
no test coverage detected