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

Sphinx automodule: class method not documented when decorated with mocked function #10310

Closed
GutiCW opened this issue Mar 30, 2022 · 1 comment

Comments

@GutiCW
Copy link

GutiCW commented Mar 30, 2022

Describe the bug

I have a class with decorated methods. The function used as a decorator is provided by a module not available when building the documentation, hence this module is mocked in conf.py using autodoc_mock_imports = ['module_with_decorator'].

.. automodule:: my_class
    :members:
from module_with_decorator import my_decorator


class MyClass:
    """
    My test class.
    """

    @staticmethod
    def my_undecorated_static_method():
        """This is my_undecorated_static_method."""

    @staticmethod
    @my_decorator(param0, param1)
    def my_decorated_static_method():
        """This is my_decorated_static_method."""

    @classmethod
    def my_undecorated_class_method(cls):
        """This is my_undecorated_class_method."""

    @classmethod
    @my_decorator(param0, param1)
    def my_decorated_class_method(cls):
        """This is my_decorated_class_method."""

    def my_undecorated_instance_method(self):
        """This is my_undecorated_instance_method."""

    @my_decorator(param0, param1)
    def my_decorated_instance_method(self):
        """This is my_decorated_instance_method."""

The decorated class methods are not shown in the documentation - others are shown correctly.

Missing class method decorated with mocked function

Any suggestions regarding this issue?

How to Reproduce

Decorate a class method with a function from a mocked module.
PowerShell:
$builder_name = "html" ; $doc_source = "...\test\doc\tp_testcase_docstring" ; $dest = "$doc_source_build$builder_name" ; conda activate $conda_env ; sphinx-build "$doc_source" "$dest" -b $builder_name

Expected behavior

The class methods should be visible in the documentation.

Your project

test.zip

Screenshots

No response

OS

Windows

Python version

3.9.7

Sphinx version

4.4.0

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

Related to stackoverflow.com.

@tk0miya
Copy link
Member

tk0miya commented Mar 30, 2022

At present, decorators on the mocked module are not working because they return mocked objects instead of functions or methods. I don't have good ideas to generate documents for them. So I marked this as "help wanted".

Please post your idea or send a PR to implement it. Thanks,

@tk0miya tk0miya added this to the 5.0.0 milestone Apr 3, 2022
@tk0miya tk0miya closed this as completed in d3949f8 Apr 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants