MCPcopy Index your code
hub / github.com/sphinx-doc/sphinx / _collect_doc_comment

Method _collect_doc_comment

sphinx/pycode/parser.py:362–401  ·  view source on GitHub ↗
(
        self,
        node: AssignmentLike,
        varnames: list[str],
        current_line: str,
    )

Source from the content-addressed store, hash-verified

360 self._collect_doc_comment(node, varnames, current_line)
361
362 def _collect_doc_comment(
363 self,
364 node: AssignmentLike,
365 varnames: list[str],
366 current_line: str,
367 ) -> None:
368 # check comments after assignment
369 parser = AfterCommentParser([
370 current_line[node.col_offset :],
371 *self.buffers[node.lineno :],
372 ])
373 parser.parse()
374 if parser.comment and comment_re.match(parser.comment):
375 for varname in varnames:
376 self.add_variable_comment(
377 varname, comment_re.sub('\\1', parser.comment)
378 )
379 self.add_entry(varname)
380 return
381
382 # check comments before assignment
383 if indent_re.match(current_line[: node.col_offset]):
384 comment_lines = []
385 for i in range(node.lineno - 1):
386 before_line = self.get_line(node.lineno - 1 - i)
387 if comment_re.match(before_line):
388 comment_lines.append(comment_re.sub('\\1', before_line))
389 else:
390 break
391
392 if comment_lines:
393 comment = dedent_docstring('\n'.join(reversed(comment_lines)))
394 for varname in varnames:
395 self.add_variable_comment(varname, comment)
396 self.add_entry(varname)
397 return
398
399 # not commented (record deforders only)
400 for varname in varnames:
401 self.add_entry(varname)
402
403 def visit(self, node: ast.AST) -> None:
404 """Updates self.previous to the given node."""

Callers 2

_handle_assignmentMethod · 0.95
visit_TypeAliasMethod · 0.95

Calls 9

parseMethod · 0.95
add_variable_commentMethod · 0.95
add_entryMethod · 0.95
get_lineMethod · 0.95
AfterCommentParserClass · 0.85
dedent_docstringFunction · 0.85
matchMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected