MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / walk_docstrings

Function walk_docstrings

graphify/extract.py:2154–2179  ·  view source on GitHub ↗
(node, parent_nid: str)

Source from the content-addressed store, hash-verified

2152
2153 # Class and function docstrings
2154 def walk_docstrings(node, parent_nid: str) -> None:
2155 t = node.type
2156 if t == "class_definition":
2157 name_node = node.child_by_field_name("name")
2158 body = node.child_by_field_name("body")
2159 if name_node and body:
2160 class_name = source[name_node.start_byte:name_node.end_byte].decode("utf-8", errors="replace")
2161 nid = _make_id(parent_nid, class_name) if parent_nid != file_nid else _make_id(stem, class_name)
2162 ds = _get_docstring(body)
2163 if ds:
2164 _add_rationale(ds[0], ds[1], nid)
2165 for child in body.children:
2166 walk_docstrings(child, nid)
2167 return
2168 if t == "function_definition":
2169 name_node = node.child_by_field_name("name")
2170 body = node.child_by_field_name("body")
2171 if name_node and body:
2172 func_name = source[name_node.start_byte:name_node.end_byte].decode("utf-8", errors="replace")
2173 nid = _make_id(parent_nid, func_name) if parent_nid != file_nid else _make_id(stem, func_name)
2174 ds = _get_docstring(body)
2175 if ds:
2176 _add_rationale(ds[0], ds[1], nid)
2177 return
2178 for child in node.children:
2179 walk_docstrings(child, parent_nid)
2180
2181 walk_docstrings(root, file_nid)
2182

Callers 1

Calls 3

_make_idFunction · 0.90
_get_docstringFunction · 0.85
_add_rationaleFunction · 0.85

Tested by

no test coverage detected