Skip to content

Properly documenting the return type in the "Returns" section when using google docstring style #137

@tazend

Description

@tazend

Hi,

I noticed that when using the google parser for docstrings, it is not possible to properly document the return type of the return value within the Returns section itself without using type annotations or giving the value an explicit name.

Example

Consider the following test function, and generate the documentation for it with the google parser:

def test_func():
    """Return an integer.

    Returns:
        int: The integer
    """
    print("Hello friends!")

This results in the following:

image

Additionally, the following warning is generated:

No type or annotation for returned value 'int'

I would however expect the following to be generated:

image

The workaround to generate the correct layout like in the above screenshot is of course using type annotations, and rewriting it like this:

def test_func() -> int:
    """Return an integer.

    Returns:
        The integer
    """
    print("Hello friends!")

However, I think it would still be useful having the ability to simply specify the return type in the "Returns" section and getting the same layout as when using type annotations (and not giving the return value a name).

The primary reason I'm asking is because I'm working on a Cython project, and the github source-code viewer is absolutely not a friend of mixing Cython code with type annotations, and displays this mess. Well, thats more of a github problem, but I'd still appreciate if it would be possible to have the correct layout generated without the use of type annotations :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions