(node, parent_nid: str)
| 5812 | |
| 5813 | # Class and function docstrings |
| 5814 | def walk_docstrings(node, parent_nid: str) -> None: |
| 5815 | t = node.type |
| 5816 | if t == "class_definition": |
| 5817 | name_node = node.child_by_field_name("name") |
| 5818 | body = node.child_by_field_name("body") |
| 5819 | if name_node and body: |
| 5820 | class_name = source[name_node.start_byte:name_node.end_byte].decode("utf-8", errors="replace") |
| 5821 | nid = _make_id(stem, class_name) |
| 5822 | ds = _get_docstring(body) |
| 5823 | if ds: |
| 5824 | _add_rationale(ds[0], ds[1], nid) |
| 5825 | for child in body.children: |
| 5826 | walk_docstrings(child, nid) |
| 5827 | return |
| 5828 | if t == "function_definition": |
| 5829 | name_node = node.child_by_field_name("name") |
| 5830 | body = node.child_by_field_name("body") |
| 5831 | if name_node and body: |
| 5832 | func_name = source[name_node.start_byte:name_node.end_byte].decode("utf-8", errors="replace") |
| 5833 | nid = _make_id(parent_nid, func_name) if parent_nid != file_nid else _make_id(stem, func_name) |
| 5834 | ds = _get_docstring(body) |
| 5835 | if ds: |
| 5836 | _add_rationale(ds[0], ds[1], nid) |
| 5837 | return |
| 5838 | for child in node.children: |
| 5839 | walk_docstrings(child, parent_nid) |
| 5840 | |
| 5841 | walk_docstrings(root, file_nid) |
| 5842 |
no test coverage detected