mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
autodoc: minor PEP8 adjustments
This commit is contained in:
parent
062492d75f
commit
57e897669d
@ -50,11 +50,13 @@ class DefDict(dict):
|
|||||||
def __init__(self, default):
|
def __init__(self, default):
|
||||||
dict.__init__(self)
|
dict.__init__(self)
|
||||||
self.default = default
|
self.default = default
|
||||||
|
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
try:
|
try:
|
||||||
return dict.__getitem__(self, key)
|
return dict.__getitem__(self, key)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return self.default
|
return self.default
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
# docutils check "if option_spec"
|
# docutils check "if option_spec"
|
||||||
return True
|
return True
|
||||||
@ -92,6 +94,7 @@ class _MockModule(object):
|
|||||||
else:
|
else:
|
||||||
return _MockModule()
|
return _MockModule()
|
||||||
|
|
||||||
|
|
||||||
def mock_import(modname):
|
def mock_import(modname):
|
||||||
if '.' in modname:
|
if '.' in modname:
|
||||||
pkg, _n, mods = modname.rpartition('.')
|
pkg, _n, mods = modname.rpartition('.')
|
||||||
@ -104,12 +107,14 @@ def mock_import(modname):
|
|||||||
ALL = object()
|
ALL = object()
|
||||||
INSTANCEATTR = object()
|
INSTANCEATTR = object()
|
||||||
|
|
||||||
|
|
||||||
def members_option(arg):
|
def members_option(arg):
|
||||||
"""Used to convert the :members: option to auto directives."""
|
"""Used to convert the :members: option to auto directives."""
|
||||||
if arg is None:
|
if arg is None:
|
||||||
return ALL
|
return ALL
|
||||||
return [x.strip() for x in arg.split(',')]
|
return [x.strip() for x in arg.split(',')]
|
||||||
|
|
||||||
|
|
||||||
def members_set_option(arg):
|
def members_set_option(arg):
|
||||||
"""Used to convert the :members: option to auto directives."""
|
"""Used to convert the :members: option to auto directives."""
|
||||||
if arg is None:
|
if arg is None:
|
||||||
@ -118,6 +123,7 @@ def members_set_option(arg):
|
|||||||
|
|
||||||
SUPPRESS = object()
|
SUPPRESS = object()
|
||||||
|
|
||||||
|
|
||||||
def annotation_option(arg):
|
def annotation_option(arg):
|
||||||
if arg is None:
|
if arg is None:
|
||||||
# suppress showing the representation of the object
|
# suppress showing the representation of the object
|
||||||
@ -125,6 +131,7 @@ def annotation_option(arg):
|
|||||||
else:
|
else:
|
||||||
return arg
|
return arg
|
||||||
|
|
||||||
|
|
||||||
def bool_option(arg):
|
def bool_option(arg):
|
||||||
"""Used to convert flag options to auto directives. (Instead of
|
"""Used to convert flag options to auto directives. (Instead of
|
||||||
directives.flag(), which returns None).
|
directives.flag(), which returns None).
|
||||||
@ -201,6 +208,7 @@ def cut_lines(pre, post=0, what=None):
|
|||||||
lines.append('')
|
lines.append('')
|
||||||
return process
|
return process
|
||||||
|
|
||||||
|
|
||||||
def between(marker, what=None, keepempty=False, exclude=False):
|
def between(marker, what=None, keepempty=False, exclude=False):
|
||||||
"""Return a listener that either keeps, or if *exclude* is True excludes,
|
"""Return a listener that either keeps, or if *exclude* is True excludes,
|
||||||
lines between lines that match the *marker* regular expression. If no line
|
lines between lines that match the *marker* regular expression. If no line
|
||||||
@ -211,6 +219,7 @@ def between(marker, what=None, keepempty=False, exclude=False):
|
|||||||
be processed.
|
be processed.
|
||||||
"""
|
"""
|
||||||
marker_re = re.compile(marker)
|
marker_re = re.compile(marker)
|
||||||
|
|
||||||
def process(app, what_, name, obj, options, lines):
|
def process(app, what_, name, obj, options, lines):
|
||||||
if what and what_ not in what:
|
if what and what_ not in what:
|
||||||
return
|
return
|
||||||
@ -719,6 +728,7 @@ class Documenter(object):
|
|||||||
elif member_order == 'bysource' and self.analyzer:
|
elif member_order == 'bysource' and self.analyzer:
|
||||||
# sort by source order, by virtue of the module analyzer
|
# sort by source order, by virtue of the module analyzer
|
||||||
tagorder = self.analyzer.tagorder
|
tagorder = self.analyzer.tagorder
|
||||||
|
|
||||||
def keyfunc(entry):
|
def keyfunc(entry):
|
||||||
fullname = entry[0].name.split('::')[1]
|
fullname = entry[0].name.split('::')[1]
|
||||||
return tagorder.get(fullname, len(tagorder))
|
return tagorder.get(fullname, len(tagorder))
|
||||||
@ -976,6 +986,7 @@ class DocstringSignatureMixin(object):
|
|||||||
self.args, self.retann = result
|
self.args, self.retann = result
|
||||||
return Documenter.format_signature(self)
|
return Documenter.format_signature(self)
|
||||||
|
|
||||||
|
|
||||||
class DocstringStripSignatureMixin(DocstringSignatureMixin):
|
class DocstringStripSignatureMixin(DocstringSignatureMixin):
|
||||||
"""
|
"""
|
||||||
Mixin for AttributeDocumenter to provide the
|
Mixin for AttributeDocumenter to provide the
|
||||||
@ -1142,7 +1153,7 @@ class ClassDocumenter(ModuleLevelDocumenter):
|
|||||||
# for new-style classes, no __init__ means default __init__
|
# for new-style classes, no __init__ means default __init__
|
||||||
if (initdocstring is not None and
|
if (initdocstring is not None and
|
||||||
(initdocstring == object.__init__.__doc__ or # for pypy
|
(initdocstring == object.__init__.__doc__ or # for pypy
|
||||||
initdocstring.strip() == object.__init__.__doc__)): #for !pypy
|
initdocstring.strip() == object.__init__.__doc__)): # for !pypy
|
||||||
initdocstring = None
|
initdocstring = None
|
||||||
if initdocstring:
|
if initdocstring:
|
||||||
if content == 'init':
|
if content == 'init':
|
||||||
@ -1272,7 +1283,7 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class AttributeDocumenter(DocstringStripSignatureMixin,ClassLevelDocumenter):
|
class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
|
||||||
"""
|
"""
|
||||||
Specialized Documenter subclass for attributes.
|
Specialized Documenter subclass for attributes.
|
||||||
"""
|
"""
|
||||||
@ -1479,7 +1490,7 @@ def add_documenter(cls):
|
|||||||
raise ExtensionError('autodoc documenter %r must be a subclass '
|
raise ExtensionError('autodoc documenter %r must be a subclass '
|
||||||
'of Documenter' % cls)
|
'of Documenter' % cls)
|
||||||
# actually, it should be possible to override Documenters
|
# actually, it should be possible to override Documenters
|
||||||
#if cls.objtype in AutoDirective._registry:
|
# if cls.objtype in AutoDirective._registry:
|
||||||
# raise ExtensionError('autodoc documenter for %r is already '
|
# raise ExtensionError('autodoc documenter for %r is already '
|
||||||
# 'registered' % cls.objtype)
|
# 'registered' % cls.objtype)
|
||||||
AutoDirective._registry[cls.objtype] = cls
|
AutoDirective._registry[cls.objtype] = cls
|
||||||
|
Loading…
Reference in New Issue
Block a user