Skip to content

Commit 698b456

Browse files
committed
Use definition lists rather than blockquotes
Make blockquote behaviour optional. Not yet tested
1 parent e32e363 commit 698b456

File tree

4 files changed

+35
-34
lines changed

4 files changed

+35
-34
lines changed

doc/install.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ The following options can be set in your Sphinx ``conf.py``:
2020
numpydoc_use_plots : bool
2121
Whether to produce ``plot::`` directives for Examples sections that
2222
contain ``import matplotlib``.
23+
numpydoc_use_blockqutoes : bool
24+
Until version 0.8, parameter definitions were shown as blockquotes, rather
25+
than in a definition list. If your styling requires blockquotes, switch
26+
this config option to True. This option will be removed in version 0.10.
2327
numpydoc_show_class_members : bool
2428
Whether to show all members of a class in the Methods and Attributes
2529
sections automatically.

numpydoc/docscrape_sphinx.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def __init__(self, docstring, config={}):
2828

2929
def load_config(self, config):
3030
self.use_plots = config.get('use_plots', False)
31+
self.use_blockquotes = config.get('use_blockquotes', False)
3132
self.class_members_toctree = config.get('class_members_toctree', True)
3233
self.template = config.get('template', None)
3334
if self.template is None:
@@ -63,18 +64,26 @@ def _str_extended_summary(self):
6364
return self['Extended Summary'] + ['']
6465

6566
def _str_returns(self, name='Returns'):
67+
if self.use_blockquotes:
68+
typed_fmt = '**%s** : %s'
69+
untyped_fmt = '**%s**'
70+
else:
71+
typed_fmt = '%s : %s'
72+
untyped_fmt = '%s'
73+
6674
out = []
6775
if self[name]:
6876
out += self._str_field_list(name)
6977
out += ['']
7078
for param, param_type, desc in self[name]:
7179
if param_type:
72-
out += self._str_indent(['**%s** : %s' % (param.strip(),
73-
param_type)])
80+
out += self._str_indent([typed_fmt % (param.strip(),
81+
param_type)])
7482
else:
75-
out += self._str_indent([param.strip()])
83+
out += self._str_indent([untyped_fmt % param.strip()])
7684
if desc:
77-
out += ['']
85+
if self.use_blockquotes:
86+
out += ['']
7887
out += self._str_indent(desc, 8)
7988
out += ['']
8089
return out
@@ -117,7 +126,7 @@ def _process_param(self, param, desc, autosum):
117126
relies on Sphinx's plugin mechanism.
118127
"""
119128
param = param.strip()
120-
display_param = '**%s**' % param
129+
display_param = ('**%s**' if self.use_blockquotes else '%s') % param
121130

122131
if autosum is None:
123132
return display_param, desc
@@ -197,7 +206,8 @@ def _str_param_list(self, name, fake_autosummary=False):
197206
else:
198207
out += self._str_indent([display_param])
199208
if desc:
200-
out += [''] # produces a blockquote, rather than a dt/dd
209+
if self.use_blockquotes:
210+
out += ['']
201211
out += self._str_indent(desc, 8)
202212
out += ['']
203213

numpydoc/numpydoc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def rename_references(app, what, name, obj, options, lines,
6565
def mangle_docstrings(app, what, name, obj, options, lines):
6666

6767
cfg = {'use_plots': app.config.numpydoc_use_plots,
68+
'use_blockquotes': app.config.numpydoc_use_blockquotes,
6869
'show_class_members': app.config.numpydoc_show_class_members,
6970
'show_inherited_class_members':
7071
app.config.numpydoc_show_inherited_class_members,
@@ -131,6 +132,7 @@ def setup(app, get_doc_object_=get_doc_object):
131132
app.connect('autodoc-process-signature', mangle_signature)
132133
app.add_config_value('numpydoc_edit_link', None, False)
133134
app.add_config_value('numpydoc_use_plots', None, False)
135+
app.add_config_value('numpydoc_use_blockquotes', None, False)
134136
app.add_config_value('numpydoc_show_class_members', True, True)
135137
app.add_config_value('numpydoc_show_inherited_class_members', True, True)
136138
app.add_config_value('numpydoc_class_members_toctree', True, True)

numpydoc/tests/test_docscrape.py

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -468,28 +468,24 @@ def test_sphinx_str():
468468
469469
:Parameters:
470470
471-
**mean** : (N,) ndarray
472-
471+
mean : (N,) ndarray
473472
Mean of the N-dimensional distribution.
474473
475474
.. math::
476475
477476
(1+2+3)/3
478477
479-
**cov** : (N, N) ndarray
480-
478+
cov : (N, N) ndarray
481479
Covariance matrix of the distribution.
482480
483-
**shape** : tuple of ints
484-
481+
shape : tuple of ints
485482
Given a shape of, for example, (m,n,k), m*n*k samples are
486483
generated, and packed in an m-by-n-by-k arrangement. Because
487484
each sample is N-dimensional, the output shape is (m,n,k,N).
488485
489486
:Returns:
490487
491-
**out** : ndarray
492-
488+
out : ndarray
493489
The drawn samples, arranged according to `shape`. If the
494490
shape given is (m,n,...), then the shape of `out` is is
495491
(m,n,...,N).
@@ -498,26 +494,22 @@ def test_sphinx_str():
498494
value drawn from the distribution.
499495
500496
list of str
501-
502497
This is not a real return value. It exists to test
503498
anonymous return values.
504499
505500
:Other Parameters:
506501
507-
**spam** : parrot
508-
502+
spam : parrot
509503
A parrot off its mortal coil.
510504
511505
:Raises:
512506
513-
**RuntimeError**
514-
507+
RuntimeError
515508
Some error
516509
517510
:Warns:
518511
519-
**RuntimeWarning**
520-
512+
RuntimeWarning
521513
Some warning
522514
523515
.. warning::
@@ -585,16 +577,13 @@ def test_sphinx_yields_str():
585577
586578
:Yields:
587579
588-
**a** : int
589-
580+
a : int
590581
The number of apples.
591582
592-
**b** : int
593-
583+
b : int
594584
The number of bananas.
595585
596586
int
597-
598587
The number of unknowns.
599588
""")
600589

@@ -1071,12 +1060,10 @@ def no_period(self):
10711060
10721061
:Parameters:
10731062
1074-
**f** : callable ``f(t, y, *f_args)``
1075-
1063+
f : callable ``f(t, y, *f_args)``
10761064
Aaa.
10771065
1078-
**jac** : callable ``jac(t, y, *jac_args)``
1079-
1066+
jac : callable ``jac(t, y, *jac_args)``
10801067
Bbb.
10811068
10821069
.. rubric:: Examples
@@ -1137,12 +1124,10 @@ def test_templated_sections():
11371124
11381125
:Parameters:
11391126
1140-
**f** : callable ``f(t, y, *f_args)``
1141-
1127+
f : callable ``f(t, y, *f_args)``
11421128
Aaa.
11431129
1144-
**jac** : callable ``jac(t, y, *jac_args)``
1145-
1130+
jac : callable ``jac(t, y, *jac_args)``
11461131
Bbb.
11471132
11481133
""")

0 commit comments

Comments
 (0)