MCPcopy
hub / github.com/PyGithub/PyGithub / leave_ClassDef

Method leave_ClassDef

scripts/openapi.py:1658–1670  ·  view source on GitHub ↗
(self, original_node: cst.ClassDef, updated_node: cst.ClassDef)

Source from the content-addressed store, hash-verified

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]

Callers

nothing calls this directly

Calls 2

find_method_indexMethod · 0.95
create_methodMethod · 0.95

Tested by

no test coverage detected