Skip to content

Docs from global variable that points to class with special members don't appear #9127

@maehster

Description

@maehster

Describe the bug
I am not sure if this is a bug or I am doing something wrong :)

But when I have the code below, the docstring of initialize won't appear in my doc html.

Surprisingly, the initialize method will appear in the docs when I remove the __call__ method from the class.

To Reproduce

from types import SimpleNamespace
from typing import Any


class Container:
    pass


class Initializer:
    def __call__(self, container_name: str, initial_content: Any = SimpleNamespace()):
        setattr(Container, container_name, initial_content)

    def __getattr__(self, container_name: str):
        return lambda initial_content = SimpleNamespace(): setattr(_Container, container_name, initial_content)


initialize = Initializer()
initialize.__doc__ = """
    This is some documentation.
"""
cd docs && \
make clean && \
sphinx-apidoc --force -e -o ./source ../<package> && \
make html

Expected behavior
Docs of initialize should appear in the docs but they do not.

Environment info

Python version: [3.8.5]
Sphinx==3.4.3
sphinx-rtd-theme==0.5.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4

extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc', 'sphinx.ext.napoleon']

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions