class DocStringVisitor(ast.NodeVisitor):
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_ |
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 |
Undocumented |
| Instance Variable | current |
Undocumented |
| Instance Variable | docstring |
Undocumented |
| Instance Variable | docstrings |
Undocumented |
| Method | _visit |
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. |
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).