You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add option to include docstrings with stubgen (#13284)
### Description
Closes#11965.
Add a --include-docstrings flag to stubgen. This was suggested in #11965
along with a use case.
When using this flag, the .pyi files will include docstrings for Python
classes and functions and for C extension functions.
The flag is optional and does not change the default stubgen behaviour.
When using the flag, the resulting function stubs that contain docstring
will no longer be one-liners, but functions without a docstring still
retain the default one-liner style.
Example input:
```python
class A:
"""class docstring"""
def func():
"""func docstring"""
...
def nodoc():
...
```
output:
```python
class A:
"""class docstring"""
def func() -> None:
"""func docstring"""
...
def nodoc() -> None: ...
```
## Test Plan
Tests `testIncludeDocstrings` and `testIgnoreDocstrings` were added to
`test-data/unit/stubgen.test` to ensure the code works as intended. All
other tests passed as well.
C extension docstrings are tested using an updated bash script
`misc/test_stubgenc.sh` with test data in
`test-data/pybind11_mypy_demo/stubgen-include-docs` in same fashion as
in an already existing test.
---------
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
0 commit comments