diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index 9f9f7dd29..f9489e91a 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -383,10 +383,15 @@ class VariableCommentPicker(ast.NodeVisitor): def visit_AsyncFunctionDef(self, node): # type: (ast.AsyncFunctionDef) -> None + """Handles AsyncFunctionDef node and set context.""" self.visit_FunctionDef(node) # type: ignore class DefinitionFinder(TokenProcessor): + """Python source code parser to detect location of functions, + classes and methods. + """ + def __init__(self, lines): # type: (List[str]) -> None super().__init__(lines) @@ -397,6 +402,7 @@ class DefinitionFinder(TokenProcessor): def add_definition(self, name, entry): # type: (str, Tuple[str, int, int]) -> None + """Add a location of definition.""" if self.indents and self.indents[-1][0] == 'def' and entry[0] == 'def': # ignore definition of inner function pass @@ -405,6 +411,7 @@ class DefinitionFinder(TokenProcessor): def parse(self): # type: () -> None + """Parse the code to obtain location of definitions.""" while True: token = self.fetch_token() if token is None: @@ -426,6 +433,7 @@ class DefinitionFinder(TokenProcessor): def parse_definition(self, typ): # type: (str) -> None + """Parse AST of definition.""" name = self.fetch_token() self.context.append(name.value) funcname = '.'.join(self.context) @@ -447,6 +455,7 @@ class DefinitionFinder(TokenProcessor): def finalize_block(self): # type: () -> None + """Finalize definition block.""" definition = self.indents.pop() if definition[0] != 'other': typ, funcname, start_pos = definition