mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-10-13 08:52:13 -05:00
Merge pull request #6321 from tk0miya/6317_docstring
Add docstring to pycode.parser
This commit is contained in:
1 file changed
+9
@@ -383,10 +383,15 @@ class VariableCommentPicker(ast.NodeVisitor):
|
|||||||
|
|
||||||
def visit_AsyncFunctionDef(self, node):
|
def visit_AsyncFunctionDef(self, node):
|
||||||
# type: (ast.AsyncFunctionDef) -> None
|
# type: (ast.AsyncFunctionDef) -> None
|
||||||
|
"""Handles AsyncFunctionDef node and set context."""
|
||||||
self.visit_FunctionDef(node) # type: ignore
|
self.visit_FunctionDef(node) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
class DefinitionFinder(TokenProcessor):
|
class DefinitionFinder(TokenProcessor):
|
||||||
|
"""Python source code parser to detect location of functions,
|
||||||
|
classes and methods.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, lines):
|
def __init__(self, lines):
|
||||||
# type: (List[str]) -> None
|
# type: (List[str]) -> None
|
||||||
super().__init__(lines)
|
super().__init__(lines)
|
||||||
@@ -397,6 +402,7 @@ class DefinitionFinder(TokenProcessor):
|
|||||||
|
|
||||||
def add_definition(self, name, entry):
|
def add_definition(self, name, entry):
|
||||||
# type: (str, Tuple[str, int, int]) -> None
|
# 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':
|
if self.indents and self.indents[-1][0] == 'def' and entry[0] == 'def':
|
||||||
# ignore definition of inner function
|
# ignore definition of inner function
|
||||||
pass
|
pass
|
||||||
@@ -405,6 +411,7 @@ class DefinitionFinder(TokenProcessor):
|
|||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
"""Parse the code to obtain location of definitions."""
|
||||||
while True:
|
while True:
|
||||||
token = self.fetch_token()
|
token = self.fetch_token()
|
||||||
if token is None:
|
if token is None:
|
||||||
@@ -426,6 +433,7 @@ class DefinitionFinder(TokenProcessor):
|
|||||||
|
|
||||||
def parse_definition(self, typ):
|
def parse_definition(self, typ):
|
||||||
# type: (str) -> None
|
# type: (str) -> None
|
||||||
|
"""Parse AST of definition."""
|
||||||
name = self.fetch_token()
|
name = self.fetch_token()
|
||||||
self.context.append(name.value)
|
self.context.append(name.value)
|
||||||
funcname = '.'.join(self.context)
|
funcname = '.'.join(self.context)
|
||||||
@@ -447,6 +455,7 @@ class DefinitionFinder(TokenProcessor):
|
|||||||
|
|
||||||
def finalize_block(self):
|
def finalize_block(self):
|
||||||
# type: () -> None
|
# type: () -> None
|
||||||
|
"""Finalize definition block."""
|
||||||
definition = self.indents.pop()
|
definition = self.indents.pop()
|
||||||
if definition[0] != 'other':
|
if definition[0] != 'other':
|
||||||
typ, funcname, start_pos = definition
|
typ, funcname, start_pos = definition
|
||||||
|
|||||||
Reference in new issue
Block a user