Skip to content

TypeVars imported from another module lose their docstring #13276

Open
@coretl

Description

@coretl

Describe the bug

If you create your TypeVars in a private module, then re-export them via a public module, they lose their type comments when documented via an automodule directive.

In the reproducer below, V appears in the output, while T does not.

I will submit a PR fixing this with the reproducer as a unit test.

How to Reproduce

mymodule/_private.py:

from typing import TypeVar

T = TypeVar("T", bound=int | str)
"""A reimported TypeVar"""

mymodule/__init__.py:

from ._private import T

from typing import TypeVar

V = TypeVar("V")
"""A locally defined TypeVar"""

__all__ = ["T", "V"]

index.rst:

.. automodule:: mymodule
    :members:

Environment Information

Platform:              linux; (Linux-4.18.0-513.24.1.el8_9.x86_64-x86_64-with-glibc2.36)
Python version:        3.11.11 (main, Dec  4 2024, 20:38:25) [GCC 12.2.0])
Python implementation: CPython
Sphinx version:        7.3.7
Docutils version:      0.21.2
Jinja2 version:        3.1.5
Pygments version:      2.19.1

Sphinx extensions

`["sphinx.ext.autodoc"]`

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions