MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_class

Method extract_class

codegraph-kernel/src/python.rs:525–562  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

523 }
524
525 fn extract_class(&mut self, node: Node<'t>) {
526 stack_guard!();
527 let name = self.extract_name(node);
528 let extra = Extra {
529 docstring: docstring_for(node, self.src),
530 ..Extra::default()
531 };
532 let Some(row) = self.create_node("class", &name, node, extra) else { return };
533
534 // Inheritance: `class Flask(Scaffold, Mixin):` — argument_list children.
535 // A parameterized base, `class Leaf(Base[str])`, is a `subscript`
536 // whose value names the class.
537 let extends_kind = edge_kind_index("extends").unwrap();
538 for child in node.named_children(&mut node.walk()) {
539 if child.kind() == "argument_list" {
540 for base in child.named_children(&mut child.walk()) {
541 let arg = if base.kind() == "subscript" {
542 let Some(value) = base.child_by_field_name("value") else { continue };
543 value
544 } else {
545 base
546 };
547 if matches!(arg.kind(), "identifier" | "attribute") {
548 let name = self.text(arg).to_string();
549 self.push_ref_at(row, &name, extends_kind, arg);
550 }
551 }
552 }
553 }
554 self.extract_decorators_for(node, row);
555
556 self.stack.push(Scope { row, kind: "class", name });
557 let body = node.child_by_field_name("body").unwrap_or(node);
558 for c in body.named_children(&mut body.walk()) {
559 self.visit_node(c);
560 }
561 self.stack.pop();
562 }
563
564 /// extractVariable's python branch: `left = right` at module scope.
565 /// Returns the right-hand side when it was walked under the assigned

Callers 2

visit_nodeMethod · 0.45

Calls 11

docstring_forFunction · 0.85
edge_kind_indexFunction · 0.85
pushMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60
extract_nameMethod · 0.45
create_nodeMethod · 0.45
walkMethod · 0.45
push_ref_atMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected