def rst_sections_in_module(tree, module_name, exports):
docstring = ast.get_docstring(tree)
if docstring:
yield docstring
for toplevel in tree.body:
try:
if toplevel.name not in exports:
continue
except AttributeError:
continue
print(
'Documenting {}.{}'.format(module_name, toplevel.name),
file=sys.stderr)
class_doc = ast.get_docstring(toplevel)
if class_doc:
yield toplevel.name + '\n' + '-' * len(toplevel.name)
yield class_doc
if type(toplevel) == ast.ClassDef:
for fun in toplevel.body:
if type(fun) != ast.FunctionDef:
continue
fun_doc = ast.get_docstring(fun)
if fun_doc:
fun_sig = signature(module_name, toplevel.name, fun)
yield fun.name + '\n' + '+' * len(fun.name)
yield 'Signature:\n ' + fun_sig
yield fun_doc
else:
if not fun.name.startswith('_'):
print('Missing docstring for ' + fun.name, file=sys.stderr)
评论列表
文章目录