Skip to content

autodoc drops docstrings for re-exported constants #12706

@MKuranowski

Description

@MKuranowski

Describe the bug

The docstrings of re-exported constants are ignored when being re-exported.

How to Reproduce

mymodule/init.py:

from .limit import DEFAULT_STEP_LIMIT
__all__ = ["DEFAULT_STEP_LIMIT"]

mymodule/limit.py:

DEFAULT_STEP_LIMIT = 1_000_000
"""DEFAULT_STEP_LIMIT is the default limit for number of steps before the algorithm
concludes no solution exists.
"""

index.rst:

mymodule documentation
======================

.. autodata:: mymodule.DEFAULT_STEP_LIMIT
.. autodata:: mymodule.limit.DEFAULT_STEP_LIMIT

conf.py

Default, generated by sphinx-quickstart, but with the autodoc extension

conf.py
project = 'mymodule'
copyright = '2024, Mikołaj Kuranowski'
author = 'Mikołaj Kuranowski'

extensions = ["sphinx.ext.autodoc"]

templates_path = ['_templates']
exclude_patterns = []

html_theme = 'alabaster'
html_static_path = ['_static']

The result is as follows:

image

The docstring for both constants should be the same (DEFAULT_STEP_LIMIT is the default limit [...]).

Environment Information

Platform:              linux; (Linux-6.10.1-arch1-1-x86_64-with-glibc2.40)
Python version:        3.12.4 (main, Jun  7 2024, 06:33:07) [GCC 14.1.1 20240522])
Python implementation: CPython
Sphinx version:        7.4.7
Docutils version:      0.21.2
Jinja2 version:        3.1.4
Pygments version:      2.18.0

Sphinx extensions

["sphinx.ext.autodoc"]

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions