Description
Bug Report
I'm using stubgen
to generate stubs for an untyped package. Because the docstrings are assembled at runtime, I want to include them in the stubs such that IDEs using static type checkers can use them. I therefore invoke stubgen
with the --include-docstrings
and --inspect-mode
parameters. The generated stubs do not include docstrings for classes (i.e., MyClass.__doc__
), while docstrings for methods and properties are correctly added to the stubs.
If I remove the --inspect-mode
switch, the class docstrings are added to the stubs as expected. But this isn't a viable solution for me, as I need to use inspect mode to generate the full docstrings.
To summarize, there seems to be an interaction between --include-docstrings
and --inspect-mode
, which causes class docstrings in MyClass.__doc__
to get lost.
To Reproduce
# mwe.py
class MyClass:
"""My test class."""
def __init__(self):
pass
def f(self):
"""My test function."""
pass
Run:
stubgen --include-docstrings --inspect-mode ./mwe.py
Expected Behavior
The type stub contains the class docstring.
class MyClass:
"""My test class."""
def __init__(self) -> None: ...
def f(self) -> None:
"""My test function."""
Actual Behavior
The type stub does not contain the class docstring.
class MyClass:
def __init__(self) -> None: ...
def f(self):
"""My test function."""
The expected stub can be produced by omitting the --inspect-mode
parameter, i.e., by invoking:
stubgen --include-docstrings ./mwe.py
Your Environment
- Mypy version used: 1.7.0
- stubgen command-line flags:
--include-docstrings --inspect-mode
- Python version used: 3.12.0