Simple code to extract class & function docstrings from a module.
This code is used as an example in the library reference manual in the section on using the parser module. Refer to the manual for a thorough discussion of the operation of this code.
The code has been extended by Stephen Davies for the Synopsis project. It now also recognises parameter names and values, and baseclasses. Names are now returned in order also.
Classes Summary: | |
SuiteInfoBase [Source] | |
SuiteFuncInfo [Source] | |
FunctionInfo [Source] | |
ClassInfo [Source] | |
ModuleInfo [Source] |
Functions Summary: | |
findModulePath(module) Return the path for the given module [Source] | |
format(tree, depth = -1) Format the given tree up to the given depth. [Source] | |
stringify(tree) Convert the given tree to a string [Source] | |
get_docs(file) Retrieve information from the parse tree of a source file. [Source] | |
filter_names(list) [Source] | |
map_second(list) [Source] | |
map_rest(list) [Source] | |
get_names_only(list) [Source] | |
match(pattern, data, vars = None) Match `data' to `pattern', with variable extraction. [Source] | |
dmatch(pattern, data, vars = None) Debugging match [Source] |
Function Details: |
Format the given tree up to the given depth. Numbers are replaced with their symbol or token names.
Retrieve information from the parse tree of a source file.
file Name of the file to read Python source code from.
Match `data' to `pattern', with variable extraction.
pattern Pattern to match against, possibly containing variables.
data Data to be checked and against which variables are extracted.
vars Dictionary of variables which have already been found. If not provided, an empty dictionary is created.
The `pattern' value may contain variables of the form ['varname'] which are allowed to match anything. The value that is matched is returned as part of a dictionary which maps 'varname' to the matched value. 'varname' is not required to be a string object, but using strings makes patterns and the code which uses them more readable.
This function returns two values: a boolean indicating whether a match was found and a dictionary mapping variable names to their associated values.