def get_variable_docstrings(filename):
def walk_node(parent, values=None, prefix="<STR_LIT>"):<EOL><INDENT>"""<STR_LIT>"""<EOL>docstrings = {}<EOL>if values is None:<EOL><INDENT>values = {}<EOL><DEDENT>key = None<EOL>for node in ast.iter_child_nodes(parent):<EOL><INDENT>if isinstance(node, ast.ClassDef):<EOL><INDENT>docs = walk_node(node, values, prefix + node.name + "<STR_LIT:.>")[<NUM_LIT:0>]<EOL>docstrings[node.name] = docs<EOL><DEDENT>elif isinstance(node, ast.Assign):<EOL><INDENT>key = node.targets[<NUM_LIT:0>].id<EOL>if isinstance(node.value, ast.Num):<EOL><INDENT>values[key] = node.value.n<EOL><DEDENT>if isinstance(node.value, ast.Str):<EOL><INDENT>values[key] = node.value.s<EOL><DEDENT>if isinstance(node.value, ast.Name):<EOL><INDENT>if node.value.id in values:<EOL><INDENT>values[prefix + key] = values[node.value.id]<EOL><DEDENT><DEDENT><DEDENT>elif isinstance(node, ast.Expr) and key:<EOL><INDENT>docstrings[key] = node.value.s<EOL><DEDENT>else:<EOL><INDENT>key = None<EOL><DEDENT><DEDENT>return docstrings, values<EOL><DEDENT>with open(filename, "<STR_LIT:r>") as f:<EOL><INDENT>source = f.read()<EOL><DEDENT>return walk_node(ast.parse(source))<EOL>
Go through the file and find all documented variables.
That is ones that have a literal expression following them.

Also get a dict of assigned values so that we can substitute constants.