class documentation

class DocStringVisitor(ast.NodeVisitor):

View In Hierarchy

A `NodeVisitor` subclass that walks an Abstract Syntax Tree (AST) and gathers up and notes the positions of any docstrings it finds.

Method __init__ Undocumented
Method visit_Expr We need to actually visit the nodes representing the docstrings to record their positions. Docstring nodes show up as `Expr` nodes whose values are `Str` nodes.
Instance Variable current_doc Undocumented
Instance Variable current_node Undocumented
Instance Variable docstring_lines Undocumented
Instance Variable docstrings Undocumented
Method _visit_docstring_node A method to be called when visiting any node that might have an associated docstring (ie, module, function and class nodes). This uses `ast.get_docstring` to grab and sanitize the docstring, and notes which node we're currently looking at.
def __init__(self):

Undocumented

def visit_Expr(self, node):

We need to actually visit the nodes representing the docstrings to record their positions. Docstring nodes show up as `Expr` nodes whose values are `Str` nodes. `ast.Str` was removed in Python 3.8 (well, deprecated and marked for removal), so we need to play around a bit... The Python docs state: A constant value. The value attribute of the Constant literal contains the Python object it represents. The values represented can be simple types such as a number, string or None, but also immutable container types (tuples and frozensets) if all of their elements are constant. ...or in English, the `node.value` **type** will be `ast.Constant` *but* you can get its actual type via `node.value.value` for constant types (`ast.Call` types don't have a `value.value` member).

current_doc =

Undocumented

current_node =

Undocumented

docstring_lines: set =

Undocumented

docstrings: dict =

Undocumented

def _visit_docstring_node(self, node):

A method to be called when visiting any node that might have an associated docstring (ie, module, function and class nodes). This uses `ast.get_docstring` to grab and sanitize the docstring, and notes which node we're currently looking at.