Skip to content

type hints are not added correctly to google style docstrings #347

@arwedus

Description

@arwedus

Problem description

I found a buggy behavior when the autoapi is configured like this in conf.py:

autodoc_typehints = "description"
autoapi_type = "python"
autoapi_file_pattern = "*.py"
autoapi_python_class_content = "both"

With the following method signature:

    def method_google_docs(self, foo: int, bar: int = 0) -> int:
        """This method is documented with google style docstrings.

        .. spec:: gdocstr example
            :links: R_PYIMPORT_2

            Provides an example for google docstrings

        Parameters:
            foo (int): The first argument.
            bar (int): The second argument.

        Returns:
            int: The sum of foo and bar.
        """
        return foo + bar

The type hints will be displayed like this:

edit: I cannot upload images for some reason (github says "something went really wrong and we can't process that file"). But it looks like this:

    Parameters:
        foo (int): The first argument. bar (int): The second argument.

    Returns:
        int: The sum of foo and bar.
    Parameters:  * foo (int) - 
                 * bar (int) -
    Return type: int

Expected behavior

With the following method signature using sphinx docstrings:

    def method_sphinx_docs(self, foo: int, bar: int = 0) -> int:
        """This method is documented with sphinx style docstrings.

        :param foo: The first argument.

        :param bar: The second argument.

        :returns: The sum of foo and bar.
        """
        return foo + bar

the type hints are rendered correctly:

    Parameters:  * foo (int) - The first argument.
                 * bar (int) - The second argument.
    Returns:     The sum of foo and bar.
    Return type: int

Example

If you want to analyze this issue on your side, I have created an example project:

https://github.com/arwedus/sphinx-autoapi-example

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions