sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.46k stars 2.1k forks source link

`:undoc-members:` option doesn't work for instance attributes #10193

Open electric-coder opened 2 years ago

electric-coder commented 2 years ago

Describe the bug

The :undoc-members: option does not include instance attributes without docstrings when used with the .. autoclass:: directive.

How to Reproduce

example.py

class Example:
    """A simple example."""

    def __init__(self, one_arg: str = "value"):

        self.instance_var1 = 123
        self.instance_var2 = one_arg

example.rst

example
*******

.. autoclass:: example.Example
    :members:
    :undoc-members:

conf.py

import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join('..', '..')))

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']

extensions = [
    'sphinx.ext.autodoc',
    'sphinx_rtd_theme'
]

autoclass_content = 'class'
autodoc_class_signature = "mixed"
autodoc_typehints = 'signature'
autodoc_preserve_defaults = True
add_module_names = False
add_function_parentheses = True
autodoc_typehints_description_target="all"

Expected behavior

Instance attributes without docstrings should be included by autodoc in the documentation if the :undoc-members: option is specified.

Your project

Personal project

Screenshots

undoc_members

OS

Windows 10 Pro

Python version

3.9.0

Sphinx version

4.4.0

Sphinx extensions

autodoc

Extra tools

None

Additional context

No response

electric-coder commented 8 months ago

@picnixz can you tag this with the repository's autodoc label please?