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

Generator docstring emitting both return type and yield type #419

Open
masaccio opened this issue Jan 23, 2024 · 0 comments
Open

Generator docstring emitting both return type and yield type #419

masaccio opened this issue Jan 23, 2024 · 0 comments

Comments

@masaccio
Copy link

Using Google-style docstrings with sphinx.ext.napoleon and sphinx_autodoc_typehints, I see both a Yields: row and a Return type: row in the Parameters table for generator methods.

Reproducer:

docs/index.rst:

.. currentmodule:: foo

.. autoclass:: Foo
   :members:

docs/conf.py:

import os
import sys

extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.napoleon",
    "sphinx_autodoc_typehints",
]

master_doc = "index"

sys.path.insert(0, os.path.abspath("../"))

foo/__init.py:

from typing import Optional, Generator

class Foo:
    def func(
        self,
        arg1: Optional[int] = None,
        arg2: Optional[int] = None,
    ) -> Generator[tuple, None, None]:
        """Summary of the func

        A sligntly longer description

        Args:
            arg1: this is argument 1
            arg2: this is argument 2

        Yields:
            tuple: strings of things

        Raises:
            IndexError:
                If bad stuff happens
        """
        pass

Output from sphinx-build -a -b html docs docs/build:

Screenshot 2024-01-23 at 07 19 56

Removing sphinx_autodoc_typehints results in the following output, but obviously loses the type hints in the parameters table:

Screenshot 2024-01-23 at 07 20 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant