Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/docc/plugins/python/cst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down