Skip to content

Commit d079dda

Browse files
committed
PEP8 fixes for numpydoc.py
1 parent 96a0fe3 commit d079dda

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

numpydoc/numpydoc.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
- Convert Parameters etc. sections to field lists.
1111
- Convert See Also section to a See also entry.
1212
- Renumber references.
13-
- Extract the signature from the docstring, if it can't be determined otherwise.
13+
- Extract the signature from the docstring, if it can't be determined
14+
otherwise.
1415
1516
.. [1] https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt
1617
@@ -39,28 +40,28 @@
3940
def mangle_docstrings(app, what, name, obj, options, lines,
4041
reference_offset=[0]):
4142

42-
cfg = dict(
43-
use_plots=app.config.numpydoc_use_plots,
44-
show_class_members=app.config.numpydoc_show_class_members,
45-
show_inherited_class_members=app.config.numpydoc_show_inherited_class_members,
46-
class_members_toctree=app.config.numpydoc_class_members_toctree,
47-
)
43+
cfg = {'use_plots': app.config.numpydoc_use_plots,
44+
'show_class_members': app.config.numpydoc_show_class_members,
45+
'show_inherited_class_members':
46+
app.config.numpydoc_show_inherited_class_members,
47+
'class_members_toctree': app.config.numpydoc_class_members_toctree}
4848

49+
u_NL = sixu('\n')
4950
if what == 'module':
5051
# Strip top title
51-
title_re = re.compile(sixu('^\\s*[#*=]{4,}\\n[a-z0-9 -]+\\n[#*=]{4,}\\s*'),
52-
re.I|re.S)
53-
lines[:] = title_re.sub(sixu(''), sixu("\n").join(lines)).split(sixu("\n"))
52+
pattern = '^\\s*[#*=]{4,}\\n[a-z0-9 -]+\\n[#*=]{4,}\\s*'
53+
title_re = re.compile(sixu(pattern), re.I | re.S)
54+
lines[:] = title_re.sub(sixu(''), u_NL.join(lines)).split(u_NL)
5455
else:
55-
doc = get_doc_object(obj, what, sixu("\n").join(lines), config=cfg)
56+
doc = get_doc_object(obj, what, u_NL.join(lines), config=cfg)
5657
if sys.version_info[0] >= 3:
5758
doc = str(doc)
5859
else:
5960
doc = unicode(doc)
60-
lines[:] = doc.split(sixu("\n"))
61+
lines[:] = doc.split(u_NL)
6162

62-
if app.config.numpydoc_edit_link and hasattr(obj, '__name__') and \
63-
obj.__name__:
63+
if (app.config.numpydoc_edit_link and hasattr(obj, '__name__') and
64+
obj.__name__):
6465
if hasattr(obj, '__module__'):
6566
v = dict(full_name=sixu("%s.%s") % (obj.__module__, obj.__name__))
6667
else:
@@ -93,24 +94,30 @@ def mangle_docstrings(app, what, name, obj, options, lines,
9394

9495
reference_offset[0] += len(references)
9596

97+
9698
def mangle_signature(app, what, name, obj, options, sig, retann):
9799
# Do not try to inspect classes that don't define `__init__`
98100
if (inspect.isclass(obj) and
99101
(not hasattr(obj, '__init__') or
100-
'initializes x; see ' in pydoc.getdoc(obj.__init__))):
102+
'initializes x; see ' in pydoc.getdoc(obj.__init__))):
101103
return '', ''
102104

103-
if not (isinstance(obj, collections.Callable) or hasattr(obj, '__argspec_is_invalid_')): return
104-
if not hasattr(obj, '__doc__'): return
105+
if not (isinstance(obj, collections.Callable) or
106+
hasattr(obj, '__argspec_is_invalid_')):
107+
return
108+
109+
if not hasattr(obj, '__doc__'):
110+
return
105111

106112
doc = SphinxDocString(pydoc.getdoc(obj))
107113
if doc['Signature']:
108114
sig = re.sub(sixu("^[^(]*"), sixu(""), doc['Signature'])
109115
return sig, sixu('')
110116

117+
111118
def setup(app, get_doc_object_=get_doc_object):
112119
if not hasattr(app, 'add_config_value'):
113-
return # probably called by nose, better bail out
120+
return # probably called by nose, better bail out
114121

115122
global get_doc_object
116123
get_doc_object = get_doc_object_
@@ -127,14 +134,15 @@ def setup(app, get_doc_object_=get_doc_object):
127134
app.add_domain(NumpyPythonDomain)
128135
app.add_domain(NumpyCDomain)
129136

130-
#------------------------------------------------------------------------------
137+
# ------------------------------------------------------------------------------
131138
# Docstring-mangling domains
132-
#------------------------------------------------------------------------------
139+
# ------------------------------------------------------------------------------
133140

134141
from docutils.statemachine import ViewList
135142
from sphinx.domains.c import CDomain
136143
from sphinx.domains.python import PythonDomain
137144

145+
138146
class ManglingDomainBase(object):
139147
directive_mangling_map = {}
140148

@@ -147,6 +155,7 @@ def wrap_mangling_directives(self):
147155
self.directives[name] = wrap_mangling_directive(
148156
self.directives[name], objtype)
149157

158+
150159
class NumpyPythonDomain(ManglingDomainBase, PythonDomain):
151160
name = 'np'
152161
directive_mangling_map = {
@@ -160,6 +169,7 @@ class NumpyPythonDomain(ManglingDomainBase, PythonDomain):
160169
}
161170
indices = []
162171

172+
163173
class NumpyCDomain(ManglingDomainBase, CDomain):
164174
name = 'np-c'
165175
directive_mangling_map = {
@@ -170,6 +180,7 @@ class NumpyCDomain(ManglingDomainBase, CDomain):
170180
'var': 'object',
171181
}
172182

183+
173184
def wrap_mangling_directive(base_directive, objtype):
174185
class directive(base_directive):
175186
def run(self):

0 commit comments

Comments
 (0)