(self, original_node: cst.ClassDef, updated_node: cst.ClassDef)
| 1656 | self.schema_added = 0 |
| 1657 | |
| 1658 | def leave_ClassDef(self, original_node: cst.ClassDef, updated_node: cst.ClassDef): |
| 1659 | if self.current_class_name == self.clazz.name: |
| 1660 | stmts = updated_node.body.body |
| 1661 | insert_idx = self.find_method_index(self.method_name, stmts) |
| 1662 | if insert_idx < len(stmts): |
| 1663 | stmt = stmts[insert_idx] |
| 1664 | if isinstance(stmt, cst.FunctionDef) and stmt.name.value == self.method_name: |
| 1665 | raise RuntimeError(f"Function '{self.method_name}' already exists") |
| 1666 | method = self.create_method() |
| 1667 | stmts = tuple(stmts[:insert_idx]) + (method,) + tuple(stmts[insert_idx:]) |
| 1668 | return updated_node.with_changes(body=updated_node.body.with_changes(body=stmts)) |
| 1669 | |
| 1670 | return updated_node |
| 1671 | |
| 1672 | def find_method_index( |
| 1673 | self, method_name: str, statements: Sequence[cst.BaseStatement] | Sequence[cst.BaseSmallStatement] |
nothing calls this directly
no test coverage detected