def introspect_docstring_lineno(api_doc):
"""
Try to determine the line number on which the given item's
docstring begins. Return the line number, or C{None} if the line
number can't be determined. The line number of the first line in
the file is 1.
"""
if api_doc.docstring_lineno is not UNKNOWN:
return api_doc.docstring_lineno
if isinstance(api_doc, ValueDoc) and api_doc.pyval is not UNKNOWN:
try:
lines, lineno = inspect.findsource(api_doc.pyval)
if not isinstance(api_doc, ModuleDoc): lineno += 1
for lineno in range(lineno, len(lines)):
if lines[lineno].split('#', 1)[0].strip():
api_doc.docstring_lineno = lineno + 1
return lineno + 1
except IOError: pass
except TypeError: pass
except IndexError:
log.warning('inspect.findsource(%s) raised IndexError'
% api_doc.canonical_name)
return None
评论列表
文章目录