numpydoc: add a recommandation on doc-styles for section entries that have a description

Open Beginner friendly
#721 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
documentation

Research direction

Start with docs/format.rst, which the issue names as the style guide to update, and review its section spacing rules and examples. The issue also suggests updating docs/example.py; confirm whether its examples cover the affected definition list sections. Done means the guide recommends a blank line after described entries while leaving undescribed listings compact, with relevant examples updated.

Written by the indexing model from the issue text.

Description

Style guide: recommend a blank line between section entries that have a description

This issue aims to improve the readability and maintainability of docstrings with long descriptions and/or many entries.

Background

The style guide states that "Line spacing and indentation are significant and should be carefully followed", but it is silent on the whitespace between the entries of a section. Its examples all use the compact ("tight") layout:

Parameters
----------
x : type
    Description of parameter `x`.
y : type
    Description of parameter `y`.

For projects that have classes or functions with many parameters, or that need very precise field descriptions, the "tight" layout reduces docstring readability in the source code.

Proposal

Add an explicit recommendation to format.rst (and update the examples to match):

When an entry of a section (Parameters, Attributes, Returns, Yields, Receives, Other Parameters, Raises, …) has a multi-line description, i.e., an indented definition block, insert a blank line after the description, before the next entry.
Entries consisting of a single line with no description are exempt, so compact listings stay compact when there is no need for over-spaced docstrings.

With that rule, the recommended form of the example above becomes:

Parameters
----------
x : type
    Description of parameter `x`.

y : type
    Description of parameter `y`.

While undescribed listings remain unchanged:

Parameters
----------
*args
**kwargs

Attributes
----------
real
imag

Motivation

  • Readability in text terminals and IDEs, which the guide explicitly prioritizes ("human readers of the text are given precedence"). With multi-line descriptions, the compact layout blurs where one parameter ends and the next begins; the blank line makes the entry boundary unambiguous, and its indentation (the description is indented, the next term is not) makes the required whitespace mechanically detectable.

  • Rendered output: in the loose layout each description is a paragraph, so the HTML/PDF output visibly separates entries, matching how readers parse them in the source.

  • Tooling: a single documented convention lets pydocstyle/ruff add an autofixable check; today every project encodes the opposite house rule in editorconfig/lint configs and the ecosystem cannot converge.

  • Consistency with existing whitespace guidance: the guide already mandates precise whitespace around headers and between Examples; the entry boundary is the last unspecified spacing rule.

Open questions

  1. SHOULD (recommend, allow legacy compact code) or MUST (validate)? I suggest recommending it for new docstrings without a mass-reformat of the existing stack. The idea is to build consensus and a written rule, not to force a massive reformat on all users.
  2. Should the rule apply to See Also two-line entries as well, or only to definition-list sections? In my opinion, it should be limited to definition-list sections only. It wouldn't make sense to over-space sections that just convey free-text information.

Happy to discuss this with you and to send a PR against docs/format.rst (and docs/example.py) once there is consensus.

Dominant language
Python
Stars
355
Forks
184
Avg merge
4h 57m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from numpy/numpydoc

All issues in numpy/numpydoc

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.