Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4d48beb

Browse files
authored
Merge pull request #15824 from timhoffm/writing-doc-default
Document doc style for default values
2 parents ae59549 + 2152551 commit 4d48beb

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

doc/devel/documenting_mpl.rst

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -426,15 +426,6 @@ precisely in the text.
426426
Generally, the `numpydoc docstring guide`_ conventions apply. The following
427427
rules expand on them where the numpydoc conventions are not specific.
428428

429-
As opposed to the numpydoc guide, parameters need not be marked as
430-
*optional* if they have a simple default. This removes unnecessary clutter.
431-
The optional aspect is already clear from the presence of a default value.
432-
More specifically
433-
434-
- use ``{name} : {type}, default: {val}`` when possible.
435-
- use ``{name} : {type}, optional`` and describe the default in the text if
436-
in cannot be explained sufficiently in the above way.
437-
438429
Use ``float`` for a type that can be any number.
439430

440431
Use ``(float, float)`` to describe a 2D position. The parentheses should be
@@ -476,8 +467,50 @@ Use abbreviated links ```.Normalize``` in the text.
476467

477468
.. code-block:: rst
478469
479-
norm : `~matplotlib.colors.Normalize`, optional
480-
A `.Normalize` instance is used to scale luminance data to 0, 1.
470+
norm : `~matplotlib.colors.Normalize`, optional
471+
A `.Normalize` instance is used to scale luminance data to 0, 1.
472+
473+
Default values
474+
~~~~~~~~~~~~~~
475+
As opposed to the numpydoc guide, parameters need not be marked as
476+
*optional* if they have a simple default:
477+
478+
- use ``{name} : {type}, default: {val}`` when possible.
479+
- use ``{name} : {type}, optional`` and describe the default in the text if
480+
it cannot be explained sufficiently in the recommended manner.
481+
482+
The default value should provide semantic information targeted at a human
483+
reader. In simple cases, it restates the value in the function signature.
484+
If applicable, units should be added.
485+
486+
.. code-block:: rst
487+
488+
Prefer:
489+
interval : int, default: 1000ms
490+
over:
491+
interval : int, default: 1000
492+
493+
If *None* is only used as a sentinel value for "parameter not specified", do
494+
not document it as the default. Depending on the context, give the actual
495+
default, or mark the parameter as optional if not specifying has no particular
496+
effect.
497+
498+
.. code-block:: rst
499+
500+
Prefer:
501+
dpi : int, default: :rc:`figure.dpi`
502+
over:
503+
dpi : int, default: None
504+
505+
Prefer:
506+
textprops : dict, optional
507+
Dictionary of keyword parameters to be passed to the
508+
`~matplotlib.text.Text` instance contained inside TextArea.
509+
over:
510+
textprops : dict, default: None
511+
Dictionary of keyword parameters to be passed to the
512+
`~matplotlib.text.Text` instance contained inside TextArea.
513+
481514
482515
``See also`` sections
483516
~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)