`FunctionDoc` round-trip strips empty lines from Parameters and breaks doctest
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 355
- Forks
- 181
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 3
Description
numpydoc 1.9.0rc0.dev0 git tip (2025-05-16)
CPython 3.12
A round-trip through FunctionDoc improperly removes empty lines after elements of Parameters.
This in turn breaks doctest.
In [1]: def f():
...: """
...: Hello world
...:
...: Parameters
...: ----------
...: foo : int
...: foo desc
...:
...: >>> x = [1, 2]
...:
...: bar: int
...: bar desc
...: """
In [2]: import doctest
In [3]: doctest.testmod()
Out[3]: TestResults(failed=0, attempted=1)
In [4]: from numpydoc.docscrape import FunctionDoc
In [5]: print(FunctionDoc(f))
.. function:: f
Hello world
Parameters
----------
foo : int
foo desc
>>> x = [1, 2]
bar: int
bar desc
In [6]: f.__doc__ = str(FunctionDoc(f))
In [7]: doctest.testmod()
ValueError: line 13 of the docstring for __main__.f has inconsistent leading whitespace: 'bar: int'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with numpydoc.docscrape.FunctionDoc and reproduce the round-trip shown in the issue under Python 3.12. Trace how empty lines in the Parameters section are rendered, then verify that assigning the rendered text back to f.doc leaves doctest.testmod() passing without inconsistent leading whitespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100