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

Method extract_class

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

Source from the content-addressed store, hash-verified

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

Callers 2

visit_nodeMethod · 0.45

Calls 10

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
push_ref_atMethod · 0.45
visit_nodeMethod · 0.45

Tested by

no test coverage detected