Skip to content

Libdoc shows an empty "Returns" section (and empty argument doc rows) for every keyword when the doc format is reST #5879

Backlog

Description

@Snooz82

Since Robot Framework 7.5, every keyword in the HTML output of Libdoc has a "Returns" section if the library uses ROBOT_LIBRARY_DOC_FORMAT = "reST", even when the keyword has no return type and its docstring has no Returns section. The section has a heading and an empty "Doc" column.

Argument rows are affected in the same way: arguments without documentation get the has-doc class and an empty doc row.

With the ROBOT and HTML doc formats, this does not happen.

Cause

LibraryDoc.convert_docs_to_html() in robot/libdocpkg/model.py also converts empty docs:

item.args.docs[arg.name] = formatter.html(arg.doc)
item.args.return_doc = formatter.html(item.args.return_doc)
for name, doc in item.args.raises.items():
    item.args.raises[name] = formatter.html(doc)

For an empty string, the formatters return:

Doc format formatter.html("")
ROBOT ''
HTML ''
TEXT '<p style="white-space: pre-wrap"></p>'
reST '<div class="document">\n</div>\n'

The template uses {{#if (or (hasVisibleReturnType returnType) returnDoc)}} and {{#if doc}}. The non-empty HTML for an empty reST (or TEXT) doc is truthy, so the section and the doc rows are shown.

Reproduction

EmptyReturns.py:

ROBOT_LIBRARY_DOC_FORMAT = "reST"


def no_return_doc(value: str) -> None:
    """Keyword without a *Returns* section."""


def with_return_doc(value: str) -> str:
    """Keyword with a *Returns* section.

    *Returns:*
      The value.
    """
    return value
$ libdoc --format JSON EmptyReturns.py out.json
No Return Doc    returnDoc = '<div class="document">\n</div>\n'   args[0].doc = '<div class="document">\n</div>\n'
With Return Doc  returnDoc = '<div class="document">\n<p>The value.</p>\n</div>\n'

# with ROBOT_LIBRARY_DOC_FORMAT = "ROBOT"
No Return Doc    returnDoc = ''
With Return Doc  returnDoc = '<p>The value.</p>'

libdoc EmptyReturns.py EmptyReturns.html shows a "Returns" heading for No Return Doc.

Expected

An empty doc stays empty after the conversion to HTML, so Libdoc shows no "Returns" section and no argument doc rows for keywords without that documentation.

Possible fix

Do not format empty docs, either in convert_docs_to_html() or once in DocFormatter.html():

def html(self, doc: str) -> str:
    return self._doc_to_html(doc) if doc else ""

The fix in DocFormatter.html() covers the keyword, init, argument, return, raises and type docs at once.

Environment

  • Robot Framework 7.5.1
  • Python 3.11
  • docutils installed (required for reST)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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