Skip to content
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

numpydoc: Return types without description not displayed correctly #54

Open
rkaminsk opened this issue Apr 30, 2019 · 4 comments

Comments

2 participants
@rkaminsk
Copy link

commented Apr 30, 2019

I am using numpydoc style docstrings. But when undocumented return types are used, then the type is displayed as normal text. For example in:

"""
Returns
-------
None
"""

When adding a description, then it is rendered correctly:

"""
Returns
-------
None
    Nothing to return.
"""

I am using pdoc 0.5.4.

@kernc kernc added the bug label Apr 30, 2019

@kernc kernc changed the title Return types without description not displayed correctly. numpydoc: Return types without description not displayed correctly Apr 30, 2019

@rkaminsk

This comment has been minimized.

Copy link
Author

commented May 2, 2019

I had a look at how this could be fixed. As far as I can see one would have to handle it as a special case similar to what is done with the See Also section. For my purposes, I simply hacked the to_html function in html.mako, which I modified already anyway. If you are interested, I can implement it a little nicer in pdoc and open a pull request.

_re_returns = re.compile(r"^(?<=Returns\n-{7}\n)(?P<type>[^\n]*)(?=(\Z|\n\Z|\n[^ ]))", re.MULTILINE)

def _rep_returns(match):
    return '{}\n    DUMMY DESRIPTION TO REMOVE'.format(match.group('type'))

def to_html(text):
    text = _re_returns.sub(_rep_returns, text)
    text = _to_html(text, module=module, link=link)
    text = text.replace('<dd>DUMMY DESRIPTION TO REMOVE</dd>', '')
    return tex
@kernc

This comment has been minimized.

Copy link
Contributor

commented May 2, 2019

I, too, thought it probably wouldn't go without special casing. I'd be interested in a solution involving md→md transformation like the one for See Also.

In fact, a Returns section with a single return type without description is not that different from See Also section with a single reference ... 🤔

@rkaminsk

This comment has been minimized.

Copy link
Author

commented May 2, 2019

In fact, a Returns section with a single return type without description is not that different from See Also section with a single reference ...

True. But at first I thought that

"""
Returns
-------
None
    Nothing to return.
"""

is rendered correctly when in fact it is not. None is set like an identifier but it is a type. Right?

@kernc

This comment has been minimized.

Copy link
Contributor

commented May 2, 2019

Right. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.