sphinx-doc / sphinx-doc/sphinx

Missing documentation of python class with decorators.

Open
#12,262 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extensions:autodoc type:bug
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the index.rst directive and the decorated Foo class in test_sphinx.py under Python 3.10 and Sphinx 5.3.0. Compare the generated documentation with the wrapped class and its bar method, then identify the relevant autodoc behavior and add coverage for the expected class documentation. Done means the decorated class is documented as Foo rather than as the decorator's wrapper function.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.