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

Napoleon emits empty "returns" sections #9932

Closed
AstraLuma opened this issue Dec 2, 2021 · 1 comment · Fixed by #10101
Closed

Napoleon emits empty "returns" sections #9932

AstraLuma opened this issue Dec 2, 2021 · 1 comment · Fixed by #10101

Comments

@AstraLuma
Copy link

Describe the bug

image

def get_task(task_id):
    """
    Get a task object

    Args:
        task_id: numeric ID of task

    Returns:
        Task:
    """

How to Reproduce

See above

Expected behavior

Don't emit the empty section

Your project

(private)

Screenshots

No response

OS

Mac, Linux/Container

Python version

3.10

Sphinx version

latest

Sphinx extensions

autodoc, intersphinx, todo, viewcode, napoleon, sphinx_inline_tabs, prettyspecialmethods

Extra tools

No response

Additional context

No response

@Gobot1234
Copy link
Contributor

I noticed this a while back and never bothered to report it as I just monkey patched a fix for this.

def _parse_returns_section(self: napoleon.NumpyDocstring, section: str) -> list[str]:
    fields = self._consume_returns_section()
    multi = len(fields) > 1
    use_rtype = False if multi else self._config.napoleon_use_rtype
    lines = []

    for _name, _type, _desc in fields:
        if use_rtype:
            field = self._format_field(_name, "", _desc)
        else:
            field = self._format_field(_name, _type, _desc)

        if multi:
            if lines:
                lines.extend(self._format_block("          * ", field))
            else:
                lines.extend(self._format_block(":returns: * ", field))
        else:
            if any(field):  # only add :returns: if there's something to say
                lines.extend(self._format_block(":returns: ", field))
            if _type and use_rtype:
                lines.extend([f":rtype: {_type}", ""])
    if lines and lines[-1]:
        lines.append("")
    return lines

this was my solution to it atleast.

@tk0miya tk0miya added this to the 4.4.0 milestone Jan 15, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants