Skip to content

FunctionDoc round-trip strips empty lines from Parameters and breaks doctest #624

Open
@crusaderky

Description

@crusaderky

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions