diff --git a/src/docc/plugins/python/cst.py b/src/docc/plugins/python/cst.py index 6e7828a..925541c 100644 --- a/src/docc/plugins/python/cst.py +++ b/src/docc/plugins/python/cst.py @@ -560,8 +560,14 @@ def enter_class_def(self, node: CstNode, cst_node: cst.ClassDef) -> Visit: self.old_stack.append(class_context) self.old_stack.append(body_context) - for cst_statement in cst_node.body.body: - self.old_stack[-1].child_offset += 1 + for index, cst_statement in enumerate(cst_node.body.body): + self.old_stack[-1].child_offset = index + if isinstance(cst_statement, cst.SimpleStatementLine): + if len(cst_statement.body) == 1: + cst_first = cst_statement.body[0] + if isinstance(cst_first, cst.Expr): + if isinstance(cst_first.value, cst.SimpleString): + continue statement = body.find_child(cst_statement) statement.visit(self) @@ -676,7 +682,10 @@ def _assign_docstring(self) -> Optional[nodes.Docstring]: try: line_parent_context = self.old_stack[-2] - sibling_index = line_parent_context.child_offset + 1 + if isinstance(line_parent_context.node.cst_node, cst.Module): + sibling_index = line_parent_context.child_offset + 1 + else: + sibling_index = line_parent_context.child_offset + 2 sibling = line_parent_context.node.children[sibling_index] except IndexError: return None