summaryrefslogtreecommitdiff
path: root/sphinx/ext/autodoc.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-01-10 21:23:39 +0100
committerGeorg Brandl <georg@python.org>2009-01-10 21:23:39 +0100
commitb068e9180365a5d74d4fb02b003d7a05f99ffac3 (patch)
treec092aa25daf519398c0d6cc84f85a568cf26440e /sphinx/ext/autodoc.py
parentd0e0acaaa1278627d70f7bbb7d823c79d3546b58 (diff)
downloadsphinx-git-b068e9180365a5d74d4fb02b003d7a05f99ffac3.tar.gz
Reformat to EOL80.
Diffstat (limited to 'sphinx/ext/autodoc.py')
-rw-r--r--sphinx/ext/autodoc.py112
1 files changed, 66 insertions, 46 deletions
diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index d0512f2be..c005e36a9 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -54,7 +54,7 @@ def get_method_type(obj):
(isinstance(obj, MethodType) and obj.im_self is not None):
return 'classmethod'
elif isinstance(obj, FunctionType) or \
- (isinstance(obj, BuiltinFunctionType) and obj.__self__ is not None):
+ (isinstance(obj, BuiltinFunctionType) and obj.__self__ is not None):
return 'staticmethod'
else:
return 'method'
@@ -193,7 +193,8 @@ class RstGenerator(object):
docstrings.append(obj.__doc__)
# skip some lines in module docstrings if configured (deprecated!)
- if what == 'module' and self.env.config.automodule_skip_lines and docstrings:
+ if what == 'module' and self.env.config.automodule_skip_lines \
+ and docstrings:
docstrings[0] = '\n'.join(docstrings[0].splitlines()
[self.env.config.automodule_skip_lines:])
@@ -212,7 +213,8 @@ class RstGenerator(object):
docstrings.append(initdocstring)
# the default is only the class docstring
- # make sure we have Unicode docstrings, then sanitize and split into lines
+ # make sure we have Unicode docstrings, then sanitize and split
+ # into lines
return [prepare_docstring(force_decode(docstring, encoding))
for docstring in docstrings]
@@ -233,8 +235,9 @@ class RstGenerator(object):
Returns a tuple of: the full name, the module name, a path of
names to get via getattr, the signature and return annotation.
"""
- # first, parse the definition -- auto directives for classes and functions
- # can contain a signature which is then used instead of an autogenerated one
+ # first, parse the definition -- auto directives for classes and
+ # functions can contain a signature which is then used instead of
+ # an autogenerated one
try:
mod, path, base, args, retann = py_ext_sig_re.match(name).groups()
except:
@@ -261,8 +264,8 @@ class RstGenerator(object):
if path:
mod = path.rstrip('.')
else:
- # if documenting a toplevel object without explicit module, it can
- # be contained in another auto directive ...
+ # if documenting a toplevel object without explicit module,
+ # it can be contained in another auto directive ...
if hasattr(self.env, 'autodoc_current_module'):
mod = self.env.autodoc_current_module
# ... or in the scope of a module directive
@@ -276,8 +279,9 @@ class RstGenerator(object):
mod_cls = path.rstrip('.')
else:
mod_cls = None
- # if documenting a class-level object without path, there must be a
- # current class, either from a parent auto directive ...
+ # if documenting a class-level object without path,
+ # there must be a current class, either from a parent
+ # auto directive ...
if hasattr(self.env, 'autodoc_current_class'):
mod_cls = self.env.autodoc_current_class
# ... or from a class directive
@@ -313,7 +317,8 @@ class RstGenerator(object):
args = None
getargs = True
if what == 'class':
- # for classes, the relevant signature is the __init__ method's
+ # for classes, the relevant signature is the
+ # __init__ method's
obj = getattr(obj, '__init__', None)
# classes without __init__ method, default __init__ or
# __init__ written in C?
@@ -334,8 +339,9 @@ class RstGenerator(object):
args = None
err = e
- result = self.env.app.emit_firstresult('autodoc-process-signature', what,
- name, obj, self.options, args, retann)
+ result = self.env.app.emit_firstresult(
+ 'autodoc-process-signature', what, name, obj,
+ self.options, args, retann)
if result:
args, retann = result
@@ -347,22 +353,24 @@ class RstGenerator(object):
else:
return ''
- def generate(self, what, name, members, add_content, indent=u'', check_module=False,
- no_docstring=False):
+ def generate(self, what, name, members, add_content, indent=u'',
+ check_module=False, no_docstring=False):
"""
Generate reST for the object in self.result.
"""
mod, objpath, args, retann = self.resolve_name(what, name)
if not mod:
# need a module to import
- self.warn('don\'t know which module to import for autodocumenting %r '
- '(try placing a "module" or "currentmodule" directive in the '
- 'document, or giving an explicit module name)' % name)
+ self.warn('don\'t know which module to import for autodocumenting '
+ '%r (try placing a "module" or "currentmodule" directive '
+ 'in the document, or giving an explicit module name)'
+ % name)
return
# fully-qualified name
fullname = mod + (objpath and '.' + '.'.join(objpath) or '')
- # the name to put into the generated directive -- doesn't contain the module
+ # the name to put into the generated directive -- doesn't contain
+ # the module
name_in_directive = '.'.join(objpath) or mod
# now, import the module and get object to document
@@ -372,8 +380,8 @@ class RstGenerator(object):
for part in objpath:
todoc = getattr(todoc, part)
except (ImportError, AttributeError), err:
- self.warn('autodoc can\'t import/find %s %r, it reported error: "%s", '
- 'please check your spelling and sys.path' %
+ self.warn('autodoc can\'t import/find %s %r, it reported error: '
+ '"%s", please check your spelling and sys.path' %
(what, str(fullname), err))
return
@@ -388,7 +396,7 @@ class RstGenerator(object):
else:
self.filename_set.add(analyzer.srcname)
- # check __module__ of object if wanted (for members not given explicitly)
+ # check __module__ of object for members not given explicitly
if check_module:
if hasattr(todoc, '__module__'):
if todoc.__module__ != mod:
@@ -417,16 +425,16 @@ class RstGenerator(object):
if what == 'module':
# Add some module-specific options
if self.options.synopsis:
- self.result.append(indent + u' :synopsis: ' + self.options.synopsis,
- '<autodoc>')
+ self.result.append(indent + u' :synopsis: ' +
+ self.options.synopsis, '<autodoc>')
if self.options.platform:
- self.result.append(indent + u' :platform: ' + self.options.platform,
- '<autodoc>')
+ self.result.append(indent + u' :platform: ' +
+ self.options.platform, '<autodoc>')
if self.options.deprecated:
self.result.append(indent + u' :deprecated:', '<autodoc>')
else:
- # Be explicit about the module, this is necessary since .. class:: doesn't
- # support a prepended module name
+ # Be explicit about the module, this is necessary since .. class::
+ # doesn't support a prepended module name
self.result.append(indent + u' :module: %s' % mod, '<autodoc>')
if self.options.noindex:
self.result.append(indent + u' :noindex:', '<autodoc>')
@@ -439,7 +447,8 @@ class RstGenerator(object):
u':class:`%s`' % b.__name__ or
u':class:`%s.%s`' % (b.__module__, b.__name__)
for b in todoc.__bases__]
- self.result.append(indent + _(u' Bases: %s') % ', '.join(bases),
+ self.result.append(indent + _(u' Bases: %s') %
+ ', '.join(bases),
'<autodoc>')
self.result.append(u'', '<autodoc>')
@@ -513,7 +522,8 @@ class RstGenerator(object):
# base classes
all_members = inspect.getmembers(todoc)
else:
- # __dict__ contains only the members directly defined in the class
+ # __dict__ contains only the members directly defined
+ # in the class
all_members = sorted(todoc.__dict__.iteritems())
else:
all_members = [(mname, getattr(todoc, mname)) for mname in members]
@@ -524,7 +534,8 @@ class RstGenerator(object):
for (membername, member) in all_members:
# if isattr is True, the member is documented as an attribute
isattr = False
- # if content is not None, no extra content from docstrings will be added
+ # if content is not None, no extra content from docstrings
+ # will be added
content = None
if want_all_members and membername.startswith('_'):
@@ -536,15 +547,18 @@ class RstGenerator(object):
skip = False
isattr = True
else:
- # ignore undocumented members if :undoc-members: is not given
+ # ignore undocumented members if :undoc-members:
+ # is not given
doc = getattr(member, '__doc__', None)
skip = not self.options.undoc_members and not doc
- # give the user a chance to decide whether this member should be skipped
+ # give the user a chance to decide whether this member
+ # should be skipped
if self.env.app:
# let extensions preprocess docstrings
skip_user = self.env.app.emit_firstresult(
- 'autodoc-skip-member', what, membername, member, skip, self.options)
+ 'autodoc-skip-member', what, membername, member,
+ skip, self.options)
if skip_user is not None:
skip = skip_user
if skip:
@@ -560,8 +574,9 @@ class RstGenerator(object):
if member.__name__ != membername:
# assume it's aliased
memberwhat = 'data'
- content = ViewList([_('alias of :class:`%s`') % member.__name__],
- source='')
+ content = ViewList(
+ [_('alias of :class:`%s`') % member.__name__],
+ source='')
elif issubclass(member, base_exception):
memberwhat = 'exception'
else:
@@ -577,8 +592,9 @@ class RstGenerator(object):
if member.__name__ != membername:
# assume it's aliased
memberwhat = 'attribute'
- content = ViewList([_('alias of :class:`%s`') % member.__name__],
- source='')
+ content = ViewList(
+ [_('alias of :class:`%s`') % member.__name__],
+ source='')
else:
memberwhat = 'class'
elif isdescriptor(member):
@@ -586,8 +602,8 @@ class RstGenerator(object):
else:
continue
- # give explicitly separated module name, so that members of inner classes
- # can be documented
+ # give explicitly separated module name, so that members
+ # of inner classes can be documented
full_membername = mod + '::' + '.'.join(objpath + [membername])
self.generate(memberwhat, full_membername, ['__all__'],
add_content=content, no_docstring=bool(content),
@@ -653,13 +669,17 @@ def members_option(arg):
def setup(app):
- mod_options = {'members': members_option, 'undoc-members': directives.flag,
- 'noindex': directives.flag, 'inherited-members': directives.flag,
- 'show-inheritance': directives.flag, 'synopsis': lambda x: x,
- 'platform': lambda x: x, 'deprecated': directives.flag}
- cls_options = {'members': members_option, 'undoc-members': directives.flag,
- 'noindex': directives.flag, 'inherited-members': directives.flag,
- 'show-inheritance': directives.flag}
+ mod_options = {
+ 'members': members_option, 'undoc-members': directives.flag,
+ 'noindex': directives.flag, 'inherited-members': directives.flag,
+ 'show-inheritance': directives.flag, 'synopsis': lambda x: x,
+ 'platform': lambda x: x, 'deprecated': directives.flag
+ }
+ cls_options = {
+ 'members': members_option, 'undoc-members': directives.flag,
+ 'noindex': directives.flag, 'inherited-members': directives.flag,
+ 'show-inheritance': directives.flag
+ }
app.add_directive('automodule', automodule_directive,
1, (1, 0, 1), **mod_options)
app.add_directive('autoclass', autoclass_directive,