sphinx-doc / sphinx-doc/sphinx
`:undoc-members:` option doesn't work for instance attributes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
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

OS
Windows 10 Pro
Python version
3.9.0
Sphinx version
4.4.0
Sphinx extensions
autodoc
Extra tools
None
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided example.py, example.rst, and conf.py reproduction, focusing on the autoclass and undoc-members behavior described in the issue. Confirm that the instance attributes are omitted, then ensure the completed behavior includes undocumented instance attributes in the generated documentation when :undoc-members: is enabled.
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
- 35/100