sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

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

Open electric-coder opened this issue 3 years ago • 1 comments

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 avatar Feb 14 '22 03:02 electric-coder

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

electric-coder avatar Feb 01 '24 03:02 electric-coder