Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
crusaderky opened this issue May 16, 2025 · 0 comments

Comments

@crusaderky
Copy link

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'
@crusaderky crusaderky changed the title FunctionDoc round-trip strips empty lines and breaks doctest FunctionDoc round-trip strips empty lines from Parameters and breaks doctest May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant