Skip to content

Commit 5ed44e0

Browse files
committed
FIX handling of parameter names ending '_'
This issue results from numpy#107: the explicit bold styling was removed because Sphinx definition lists bolded the term by default. However, without ** surrounding param name, a name like word_ was being treated as a link. I also attempted to replace the _ with \_ but found that the backslashes showed in the HTML. Thus I have reverted to wrapping param names in **.
1 parent 5b1169f commit 5ed44e0

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

numpydoc/docscrape_sphinx.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@ def _str_extended_summary(self):
6767
return self['Extended Summary'] + ['']
6868

6969
def _str_returns(self, name='Returns'):
70-
if self.use_blockquotes:
71-
typed_fmt = '**%s** : %s'
72-
untyped_fmt = '**%s**'
73-
else:
74-
typed_fmt = '%s : %s'
75-
untyped_fmt = '%s'
70+
typed_fmt = '**%s** : %s'
71+
untyped_fmt = '**%s**'
7672

7773
out = []
7874
if self[name]:
@@ -126,7 +122,9 @@ def _process_param(self, param, desc, fake_autosummary):
126122
relies on Sphinx's plugin mechanism.
127123
"""
128124
param = param.strip()
129-
display_param = ('**%s**' if self.use_blockquotes else '%s') % param
125+
# XXX: If changing the following, please check the rendering when param
126+
# ends with '_', e.g. 'word_'
127+
display_param = '**%s**' % param
130128

131129
if not fake_autosummary:
132130
return display_param, desc

numpydoc/tests/test_docscrape.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -477,48 +477,48 @@ def test_sphinx_str():
477477
478478
:Parameters:
479479
480-
mean : (N,) ndarray
480+
**mean** : (N,) ndarray
481481
Mean of the N-dimensional distribution.
482482
483483
.. math::
484484
485485
(1+2+3)/3
486486
487-
cov : (N, N) ndarray
487+
**cov** : (N, N) ndarray
488488
Covariance matrix of the distribution.
489489
490-
shape : tuple of ints
490+
**shape** : tuple of ints
491491
Given a shape of, for example, (m,n,k), m*n*k samples are
492492
generated, and packed in an m-by-n-by-k arrangement. Because
493493
each sample is N-dimensional, the output shape is (m,n,k,N).
494494
495495
:Returns:
496496
497-
out : ndarray
497+
**out** : ndarray
498498
The drawn samples, arranged according to `shape`. If the
499499
shape given is (m,n,...), then the shape of `out` is is
500500
(m,n,...,N).
501501
502502
In other words, each entry ``out[i,j,...,:]`` is an N-dimensional
503503
value drawn from the distribution.
504504
505-
list of str
505+
**list of str**
506506
This is not a real return value. It exists to test
507507
anonymous return values.
508508
509509
:Other Parameters:
510510
511-
spam : parrot
511+
**spam** : parrot
512512
A parrot off its mortal coil.
513513
514514
:Raises:
515515
516-
RuntimeError
516+
**RuntimeError**
517517
Some error
518518
519519
:Warns:
520520
521-
RuntimeWarning
521+
**RuntimeWarning**
522522
Some warning
523523
524524
.. warning::
@@ -586,13 +586,13 @@ def test_sphinx_yields_str():
586586
587587
:Yields:
588588
589-
a : int
589+
**a** : int
590590
The number of apples.
591591
592-
b : int
592+
**b** : int
593593
The number of bananas.
594594
595-
int
595+
**int**
596596
The number of unknowns.
597597
""")
598598

@@ -1119,10 +1119,10 @@ def no_period(self):
11191119
11201120
:Parameters:
11211121
1122-
f : callable ``f(t, y, *f_args)``
1122+
**f** : callable ``f(t, y, *f_args)``
11231123
Aaa.
11241124
1125-
jac : callable ``jac(t, y, *jac_args)``
1125+
**jac** : callable ``jac(t, y, *jac_args)``
11261126
Bbb.
11271127
11281128
.. rubric:: Examples
@@ -1131,10 +1131,10 @@ def no_period(self):
11311131
11321132
:Attributes:
11331133
1134-
t : float
1134+
**t** : float
11351135
Current time.
11361136
1137-
y : ndarray
1137+
**y** : ndarray
11381138
Current variable values.
11391139
11401140
* hello
@@ -1143,10 +1143,10 @@ def no_period(self):
11431143
:obj:`an_attribute <an_attribute>` : float
11441144
Test attribute
11451145
1146-
no_docstring : str
1146+
**no_docstring** : str
11471147
But a description
11481148
1149-
no_docstring2 : str
1149+
**no_docstring2** : str
11501150
11511151
:obj:`multiline_sentence <multiline_sentence>`
11521152
This is a sentence.
@@ -1179,10 +1179,10 @@ def test_templated_sections():
11791179
11801180
:Parameters:
11811181
1182-
f : callable ``f(t, y, *f_args)``
1182+
**f** : callable ``f(t, y, *f_args)``
11831183
Aaa.
11841184
1185-
jac : callable ``jac(t, y, *jac_args)``
1185+
**jac** : callable ``jac(t, y, *jac_args)``
11861186
Bbb.
11871187
11881188
""")

0 commit comments

Comments
 (0)