Skip to content

Libdoc: Argument and return value documentation syntax #5604

Description

@pekkaklarck

Libdoc shows keyword arguments separately and lists their names, "kind" (positional-only, varargs, ...), possible type (str, int, ...) and possible default value. There is, however, no way to include argument documentation in this listing. Instead, arguments need to be documented as part of the normal keyword documentation using whatever approach found usable. Libdoc also shows return value type, but it does not support documentation either.

We should change this and make it possible to specify argument and return value documentation explicitly so that it could be listed along with other argument and return value related information. This syntax should also play well with other tools such as IDEs and API doc generators. In practice we thus should use syntax that's used for arguments with Python normally. Unfortunately there is no official standard for that and different projects have used different approaches. The three most commonly used argument documentation styles are:

  1. The Sphinx style. This is what we currently use with Robot's API docs. In that usage it has worked fine, but the syntax is pretty complicate and verbose. It also doesn't render nicely as Markdown that we plan to support with Libdoc (Libdoc: Support documentation written with Markdown #5304).
  2. The NumPy style. This style is used primarily in the scientific Python circles. but nobody would prevent us from using it. It's simpler than the Sphinx style, but it still requires quite a bit of markers and doesn't work with with Markdown.
  3. The Google style. This is the simplest format and works very well also in source code. An example using this style is below.
def example(first: int, second: float) -> float:
    """Example keyword.

    Args:
        first: The doc for the first parameter.
        second: Also the second parameter has documentation.
          It is split to multiple lines.

    Return:
        The sum of the given arguments.
    """
    return a + b

The Google style is my clear favorite. It could be used both with library keywords and user keywords, and we probably could support it both with Markdown and with Robot's own documentation format. The Google style has its own problems, though::

  1. Also this syntax doesn't work too well with standard Markdown. For example, the block of text starting with Args: is parsed as a single paragraph so you end up with a paragraph starting with Args: second: The doc for the first .... The situation gets better if you add an empty line after Args:. In that case rest of the block is considered a code block and rendered as preformatted text. Not great but massively better than alternatives.
  2. Also the old Robot format parses the whole Args: block as a paragraph and this time adding an empty row just causes there to be two paragraphs. We may need to enhance the Robot format to support this argument documentation style better.
  3. The syntax isn't specified in detailed level and there are various flavors with the headers. The spec I linked above lists headers Args:, Returns:/Yields: and Raises:, but I've seen also seen Args: replaced with Arguments: and Parameters: and some extra headers being used.
  4. The syntax supports type information in documentation like first (int): The doc .... That was useful in Python 2 days, but nowadays it's better to use annotations and the linked docs don't even show this syntax (see here for an example that shows it). I believe we should understand this syntax, but I also believe we should just ignore the type information. We don't want to parse keyword docs during execution for performance reasons, so the type information wouldn't actually be used and showing it in Libdoc UI would be misleading.

Luckily we can solve these problems with some extra work:

  1. Decide which flavor of the Google style we support. This includes deciding which headers to support and whether we should support specifying argument types (type hints generally work better).
  2. Implement a parser for the flavor we support. It should read argument docs so that we can add them to Libdoc model along with argument names and types. Docs should then be shown in the Libdoc UI along with other argument information.
  3. Remove argument documentation from the overall docs. No need to show the same information twice and this also avoids problems with Markdown formatting.

Activity

  1. added this to the v7.5 milestone on Jan 21, 2026
  2. Huaian666 commented on Jun 12, 2026

    @Huaian666

    was just about to open the same issue. the current docs skip over this part entirely. had to read source

  3. changed the title [-]Libdoc: Dedicated syntax for argument and return value documentation[/-] [+]Libdoc: Argument and return value documentation syntax[/+] on Jun 16, 2026
  4. pekkaklarck commented on Jun 16, 2026

    @pekkaklarck
    MemberAuthor

    While reviewing #5684 I noticed there are two design decisions to be made:

    1. According to the spec, varargs and kwargs should be documented using *args and **kws syntax, respectively. We obviously should follow the spec here and allow documentation like *args: The doc. The question is, should we also support omitting * and ** like args: The doc? I believe that makes sense in general and I'm afraid reporting error if someone has used args when we require *args would also be complicated.

    2. What syntax to use with user keyword arguments? Alternatives are requiring either arg: The doc or ${arg}: The doc and supporting both. I don't have strong preference between either of the alternatives and believe supporting both would be simplest. If I needed to choose one syntax, I'd go with arg: The doc, because we only show arg, not ${arg} in Libdoc HTML docs. Not supporting ${arg}: The doc when the actual signature uses ${arg} would likely be confusing, though, and also in this case error reporting if someone has used the wrong format would be complicated.

    Both of the above could be implemented in the lower level documentation parser so that it normalizes names. In practice *arg, **arg, ${arg}, @{arg} and &{arg} should all be normalized to arg. We could implement this so that the first two work only with library keywords and the last three only with user keywords, but I see no concrete benefits with that.

    Notice that internally the ArgumentSpec object anyway stores only argument names without any decoration. We thus need to normalize names at some point anyway.

  5. 15 remaining items

  6. pekkaklarck commented on Jul 15, 2026

    @pekkaklarck
    MemberAuthor

    After my previous comment we have done, at least, the following:

    • Documentation is shown in Libdoc HTML UI.
    • Also the Raises: section is handled. This information is added to the spec files and shown in the UI.
    • Support for the old Tags: section has been improved (Enhance parsing tags from keyword documentation #5707).
    • The syntax has been documented in the User Guide.

    See the linked commits above for more details. After all this we can consider this issue done. We can still make adjustments to the UI styles if needed.

  7. added a commit that references this issue on Jul 15, 2026
    6bdcc5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acknowledgebeta 1priority: critical

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions