Skip to content

Commit 254494c

Browse files
committed
PEP8 fixes for docscrape.py
1 parent d079dda commit 254494c

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

numpydoc/docscrape.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ def __init__(self, data):
2424
String with lines separated by '\n'.
2525
2626
"""
27-
if isinstance(data,list):
27+
if isinstance(data, list):
2828
self._str = data
2929
else:
30-
self._str = data.split('\n') # store string as list of lines
30+
self._str = data.split('\n') # store string as list of lines
3131

3232
self.reset()
3333

3434
def __getitem__(self, n):
3535
return self._str[n]
3636

3737
def reset(self):
38-
self._l = 0 # current line nr
38+
self._l = 0 # current line nr
3939

4040
def read(self):
4141
if not self.eof():
@@ -67,16 +67,18 @@ def read_to_condition(self, condition_func):
6767

6868
def read_to_next_empty_line(self):
6969
self.seek_next_non_empty_line()
70+
7071
def is_empty(line):
7172
return not line.strip()
73+
7274
return self.read_to_condition(is_empty)
7375

7476
def read_to_next_unindented_line(self):
7577
def is_unindented(line):
7678
return (line.strip() and (len(line.lstrip()) == len(line)))
7779
return self.read_to_condition(is_unindented)
7880

79-
def peek(self,n=0):
81+
def peek(self, n=0):
8082
if self._l + n < len(self._str):
8183
return self[self._l + n]
8284
else:
@@ -139,25 +141,27 @@ def _is_at_section(self):
139141
if l1.startswith('.. index::'):
140142
return True
141143

142-
l2 = self._doc.peek(1).strip() # ---------- or ==========
144+
l2 = self._doc.peek(1).strip() # ---------- or ==========
143145
return l2.startswith('-'*len(l1)) or l2.startswith('='*len(l1))
144146

145-
def _strip(self,doc):
147+
def _strip(self, doc):
146148
i = 0
147149
j = 0
148-
for i,line in enumerate(doc):
149-
if line.strip(): break
150+
for i, line in enumerate(doc):
151+
if line.strip():
152+
break
150153

151-
for j,line in enumerate(doc[::-1]):
152-
if line.strip(): break
154+
for j, line in enumerate(doc[::-1]):
155+
if line.strip():
156+
break
153157

154158
return doc[i:len(doc)-j]
155159

156160
def _read_to_next_section(self):
157161
section = self._doc.read_to_next_empty_line()
158162

159163
while not self._is_at_section() and not self._doc.eof():
160-
if not self._doc.peek(-1).strip(): # previous line was empty
164+
if not self._doc.peek(-1).strip(): # previous line was empty
161165
section += ['']
162166

163167
section += self._doc.read_to_next_empty_line()
@@ -169,14 +173,14 @@ def _read_sections(self):
169173
data = self._read_to_next_section()
170174
name = data[0].strip()
171175

172-
if name.startswith('..'): # index section
176+
if name.startswith('..'): # index section
173177
yield name, data[1:]
174178
elif len(data) < 2:
175179
yield StopIteration
176180
else:
177181
yield name, self._strip(data[2:])
178182

179-
def _parse_param_list(self,content):
183+
def _parse_param_list(self, content):
180184
r = Reader(content)
181185
params = []
182186
while not r.eof():
@@ -189,13 +193,13 @@ def _parse_param_list(self,content):
189193
desc = r.read_to_next_unindented_line()
190194
desc = dedent_lines(desc)
191195

192-
params.append((arg_name,arg_type,desc))
196+
params.append((arg_name, arg_type, desc))
193197

194198
return params
195199

196-
197200
_name_rgx = re.compile(r"^\s*(:(?P<role>\w+):`(?P<name>[a-zA-Z0-9_.-]+)`|"
198201
r" (?P<name2>[a-zA-Z0-9_.-]+))\s*", re.X)
202+
199203
def _parse_see_also(self, content):
200204
"""
201205
func_name : Descriptive text
@@ -228,7 +232,8 @@ def push_item(name, rest):
228232
rest = []
229233

230234
for line in content:
231-
if not line.strip(): continue
235+
if not line.strip():
236+
continue
232237

233238
m = self._name_rgx.match(line)
234239
if m and line[m.end():].strip().startswith(':'):
@@ -307,7 +312,8 @@ def _parse(self):
307312

308313
for (section, content) in sections:
309314
if not section.startswith('..'):
310-
section = ' '.join([s.capitalize() for s in section.split(' ')])
315+
section = (s.capitalize() for s in section.split(' '))
316+
section = ' '.join(section)
311317
if section in ('Parameters', 'Returns', 'Yields', 'Raises',
312318
'Warns', 'Other Parameters', 'Attributes',
313319
'Methods'):
@@ -332,7 +338,7 @@ def _str_indent(self, doc, indent=4):
332338

333339
def _str_signature(self):
334340
if self['Signature']:
335-
return [self['Signature'].replace('*','\*')] + ['']
341+
return [self['Signature'].replace('*', '\*')] + ['']
336342
else:
337343
return ['']
338344

@@ -352,7 +358,7 @@ def _str_param_list(self, name):
352358
out = []
353359
if self[name]:
354360
out += self._str_header(name)
355-
for param,param_type,desc in self[name]:
361+
for param, param_type, desc in self[name]:
356362
if param_type:
357363
out += ['%s : %s' % (param, param_type)]
358364
else:
@@ -370,7 +376,8 @@ def _str_section(self, name):
370376
return out
371377

372378
def _str_see_also(self, func_role):
373-
if not self['See Also']: return []
379+
if not self['See Also']:
380+
return []
374381
out = []
375382
out += self._str_header("See Also")
376383
last_had_desc = True
@@ -397,7 +404,7 @@ def _str_see_also(self, func_role):
397404
def _str_index(self):
398405
idx = self['index']
399406
out = []
400-
out += ['.. index:: %s' % idx.get('default','')]
407+
out += ['.. index:: %s' % idx.get('default', '')]
401408
for section, references in idx.items():
402409
if section == 'default':
403410
continue
@@ -414,33 +421,35 @@ def __str__(self, func_role=''):
414421
out += self._str_param_list(param_list)
415422
out += self._str_section('Warnings')
416423
out += self._str_see_also(func_role)
417-
for s in ('Notes','References','Examples'):
424+
for s in ('Notes', 'References', 'Examples'):
418425
out += self._str_section(s)
419426
for param_list in ('Attributes', 'Methods'):
420427
out += self._str_param_list(param_list)
421428
out += self._str_index()
422429
return '\n'.join(out)
423430

424431

425-
def indent(str,indent=4):
432+
def indent(str, indent=4):
426433
indent_str = ' '*indent
427434
if str is None:
428435
return indent_str
429436
lines = str.split('\n')
430437
return '\n'.join(indent_str + l for l in lines)
431438

439+
432440
def dedent_lines(lines):
433441
"""Deindent a list of lines maximally"""
434442
return textwrap.dedent("\n".join(lines)).split("\n")
435443

444+
436445
def header(text, style='-'):
437446
return text + '\n' + style*len(text) + '\n'
438447

439448

440449
class FunctionDoc(NumpyDocString):
441450
def __init__(self, func, role='func', doc=None, config={}):
442451
self._f = func
443-
self._role = role # e.g. "func" or "meth"
452+
self._role = role # e.g. "func" or "meth"
444453

445454
if doc is None:
446455
if func is None:
@@ -457,7 +466,7 @@ def __init__(self, func, role='func', doc=None, config={}):
457466
else:
458467
argspec = inspect.getargspec(func)
459468
argspec = inspect.formatargspec(*argspec)
460-
argspec = argspec.replace('*','\*')
469+
argspec = argspec.replace('*', '\*')
461470
signature = '%s%s' % (func_name, argspec)
462471
except TypeError as e:
463472
signature = '%s()' % func_name
@@ -483,7 +492,7 @@ def __str__(self):
483492
if self._role:
484493
if self._role not in roles:
485494
print("Warning: invalid role %s" % self._role)
486-
out += '.. %s:: %s\n \n\n' % (roles.get(self._role,''),
495+
out += '.. %s:: %s\n \n\n' % (roles.get(self._role, ''),
487496
func_name)
488497

489498
out += super(FunctionDoc, self).__str__(func_role=self._role)
@@ -500,8 +509,8 @@ def __init__(self, cls, doc=None, modulename='', func_doc=FunctionDoc,
500509
raise ValueError("Expected a class or None, but got %r" % cls)
501510
self._cls = cls
502511

503-
self.show_inherited_members = config.get('show_inherited_class_members',
504-
True)
512+
self.show_inherited_members = config.get(
513+
'show_inherited_class_members', True)
505514

506515
if modulename and not modulename.endswith('.'):
507516
modulename += '.'

0 commit comments

Comments
 (0)