Skip to content

Commit fd17df0

Browse files
authored
fix spliting of parameter lines. (#279)
if ' : ' is present twice in the line this drops any test after the second ' : ', which happens in some docstring that have the `default : stuff` idiom
1 parent 795afa8 commit fd17df0

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

numpydoc/docscrape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _parse_param_list(self, content, single_element_is_type=False):
224224
while not r.eof():
225225
header = r.read().strip()
226226
if ' : ' in header:
227-
arg_name, arg_type = header.split(' : ')[:2]
227+
arg_name, arg_type = header.split(' : ', maxsplit=1)
228228
else:
229229
if single_element_is_type:
230230
arg_name, arg_type = '', header

numpydoc/tests/test_docscrape.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
Given a shape of, for example, (m,n,k), m*n*k samples are
4646
generated, and packed in an m-by-n-by-k arrangement. Because
4747
each sample is N-dimensional, the output shape is (m,n,k,N).
48+
dtype : data type object, optional (default : float)
49+
The type and size of the data to be returned.
4850
4951
Returns
5052
-------
@@ -181,7 +183,7 @@ def test_extended_summary():
181183

182184

183185
def test_parameters():
184-
assert len(doc['Parameters']) == 3
186+
assert len(doc['Parameters']) == 4
185187
names = [n for n, _, _ in doc['Parameters']]
186188
assert all(a == b for a, b in zip(names, ['mean', 'cov', 'shape']))
187189

@@ -190,6 +192,17 @@ def test_parameters():
190192
assert desc[0].startswith('Covariance matrix')
191193
assert doc['Parameters'][0][-1][-1] == ' (1+2+3)/3'
192194

195+
arg, arg_type, desc = doc['Parameters'][2]
196+
assert arg == 'shape'
197+
assert arg_type == 'tuple of ints'
198+
assert desc[0].startswith('Given')
199+
assert doc['Parameters'][0][-1][-1] == ' (1+2+3)/3'
200+
201+
arg, arg_type, desc = doc['Parameters'][3]
202+
assert arg == 'dtype'
203+
assert arg_type == 'data type object, optional (default : float)'
204+
assert desc[0].startswith('The type and size')
205+
193206

194207
def test_other_parameters():
195208
assert len(doc['Other Parameters']) == 1
@@ -206,7 +219,7 @@ def test_returns():
206219
assert arg_type == 'ndarray'
207220
assert desc[0].startswith('The drawn samples')
208221
assert desc[-1].endswith('distribution.')
209-
222+
210223
arg, arg_type, desc = doc['Returns'][1]
211224
assert arg == ''
212225
assert arg_type == 'list of str'
@@ -395,6 +408,8 @@ def test_str():
395408
Given a shape of, for example, (m,n,k), m*n*k samples are
396409
generated, and packed in an m-by-n-by-k arrangement. Because
397410
each sample is N-dimensional, the output shape is (m,n,k,N).
411+
dtype : data type object, optional (default : float)
412+
The type and size of the data to be returned.
398413
399414
Returns
400415
-------
@@ -563,6 +578,9 @@ def test_sphinx_str():
563578
generated, and packed in an m-by-n-by-k arrangement. Because
564579
each sample is N-dimensional, the output shape is (m,n,k,N).
565580
581+
**dtype** : data type object, optional (default : float)
582+
The type and size of the data to be returned.
583+
566584
:Returns:
567585
568586
**out** : ndarray

0 commit comments

Comments
 (0)