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

Method _handle_assignment

sphinx/pycode/parser.py:340–360  ·  view source on GitHub ↗

Handles Assign node and pick up a variable comment.

(self, node: ast.Assign | ast.AnnAssign)

Source from the content-addressed store, hash-verified

338 return self.buffers[lineno - 1]
339
340 def _handle_assignment(self, node: ast.Assign | ast.AnnAssign) -> None:
341 """Handles Assign node and pick up a variable comment."""
342 try:
343 targets = get_assign_targets(node)
344 varnames: list[str] = functools.reduce(
345 operator.iadd,
346 [get_lvar_names(t, self=self.get_self()) for t in targets],
347 [],
348 )
349 current_line = self.get_line(node.lineno)
350 except TypeError:
351 return # this assignment is not new definition!
352
353 # record annotation
354 if hasattr(node, 'annotation') and node.annotation:
355 for varname in varnames:
356 self.add_variable_annotation(varname, node.annotation)
357 elif hasattr(node, 'type_comment') and node.type_comment:
358 for varname in varnames:
359 self.add_variable_annotation(varname, node.type_comment) # type: ignore[arg-type]
360 self._collect_doc_comment(node, varnames, current_line)
361
362 def _collect_doc_comment(
363 self,

Callers 2

visit_AssignMethod · 0.95
visit_AnnAssignMethod · 0.95

Calls 6

get_selfMethod · 0.95
get_lineMethod · 0.95
_collect_doc_commentMethod · 0.95
get_assign_targetsFunction · 0.85
get_lvar_namesFunction · 0.85

Tested by

no test coverage detected