Skip to content

Commit cd1df97

Browse files
committed
fix spliting of parameter lines.
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 4e7c5ad commit cd1df97

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
@@ -220,7 +220,7 @@ def _parse_param_list(self, content, single_element_is_type=False):
220220
while not r.eof():
221221
header = r.read().strip()
222222
if ' : ' in header:
223-
arg_name, arg_type = header.split(' : ')[:2]
223+
arg_name, arg_type = header.split(' : ', maxsplit=1)
224224
else:
225225
if single_element_is_type:
226226
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
-------
@@ -180,7 +182,7 @@ def test_extended_summary():
180182

181183

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

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

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

193206
def test_other_parameters():
194207
assert len(doc['Other Parameters']) == 1
@@ -205,7 +218,7 @@ def test_returns():
205218
assert arg_type == 'ndarray'
206219
assert desc[0].startswith('The drawn samples')
207220
assert desc[-1].endswith('distribution.')
208-
221+
209222
arg, arg_type, desc = doc['Returns'][1]
210223
assert arg == ''
211224
assert arg_type == 'list of str'
@@ -394,6 +407,8 @@ def test_str():
394407
Given a shape of, for example, (m,n,k), m*n*k samples are
395408
generated, and packed in an m-by-n-by-k arrangement. Because
396409
each sample is N-dimensional, the output shape is (m,n,k,N).
410+
dtype : data type object, optional (default : float)
411+
The type and size of the data to be returned.
397412
398413
Returns
399414
-------
@@ -560,6 +575,9 @@ def test_sphinx_str():
560575
generated, and packed in an m-by-n-by-k arrangement. Because
561576
each sample is N-dimensional, the output shape is (m,n,k,N).
562577
578+
**dtype** : data type object, optional (default : float)
579+
The type and size of the data to be returned.
580+
563581
:Returns:
564582
565583
**out** : ndarray

0 commit comments

Comments
 (0)