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

Missing documentation of python class with decorators. #12262

Open
kangcliff opened this issue Apr 11, 2024 · 1 comment
Open

Missing documentation of python class with decorators. #12262

kangcliff opened this issue Apr 11, 2024 · 1 comment

Comments

@kangcliff
Copy link

Describe the bug

When generating documentation for class with decorators, Sphinx recognizes the wrapped class as the wrapper function returned by the top decorator instead of the actual class being wrapped by decorators.

How to Reproduce

index.rst

.. automodule:: test_sphinx
    :members:
    :show-inheritance:
    :undoc-members:

test_sphinx.py

def Singleton(class_):
    """A singleton decorator"""
    instances = {}

    def getinstance(*args, **kwargs):
        if class_ not in instances:
            instances[class_] = class_(*args, **kwargs)
        return instances[class_]

    return getinstance

@Singleton
class Foo:
   """An example class."""

   def bar(self):
      """An example function."""
      pass

Environment Information

Platform:              Ubuntu 22.04;
Python version:        3.10.13 (GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-44).GCC: (GNU) 7.3.1 20180303 (Red Hat 7.3.1-5).)
Python implementation: CPython
Sphinx version:        5.3.0

Sphinx extensions

No response

Additional context

No response

@picnixz
Copy link
Member

picnixz commented Apr 12, 2024

I confirmed the behaviour. At runtime, Singleton is a function and not a class anymore and it appears we do not statically analyze the decorated class before choosing the correct documenter. I think the reason why it's like this is because the documenter being involved is the one for documenting functions (since the runtime type is a function) and not a class anymore; however, IIRC, the documenter is determined before the module is statically analyzed...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants