Skip to content

The "include-docstrings" option doesn't work #16114

Open
@lmbelo

Description

@lmbelo

After cloning the latest Mypy version available on GitHub, I see the "include-docstrings" option available, but running stubgen on an extension module that provides docstrings results in no docstrings at all.

To Reproduce

git clone https://github.com/python/mypy.git
python -m build
python -m pip install mypy-1.7.0+dev-py3-none-any.whl
stubgen --include-docstrings -p myextmodule[.pyd]
python -m mypy.stubgen --include-docstrings -p myextmodule[.pyd]

Expected Behavior

The .pyi file generated from stubgen should contain docstrings declared in the extension module, for classes and functions.

Actual Behavior

There is no docstrings at all, but they exist in the extension module. I have confirmed using help(myextmodule).

Your Environment

python 3.11 for Windows x64
myextmodule installed onto site-packages

  • Mypy version used: 1.7.0+dev
  • Mypy command-line flags: --include-docstrings -p myextmodule
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: cp3.11

I know this is a new feature, but it seems not to work out.

Activity

lmbelo

lmbelo commented on Sep 15, 2023

@lmbelo
Author

My POV:

  1. Function "generate_c_function_stub" will never get functions docstring. The condition to include the docstring will never be fulfilled.
def generate_c_function_stub(...):
...
(336)    docstr: str | None = None
...
(393)    if include_docstrings and docstr:
...

The "docstr" variable is never assigned.

  1. Function "generate_c_type_stub" doesn't accomplish docstrings.

  2. Function "generate_c_property_stub" doesn't accomplish docstrings.

I have it fixed/enhanced. I'm sending a pull request.

added 2 commits that reference this issue on Sep 17, 2023
a7a47a8
c011a06
added a commit that references this issue on Sep 17, 2023
07df68d
Social-Mean

Social-Mean commented on Nov 4, 2023

@Social-Mean

I am facing the same problem.

I use pybind11 to generate a pyd file, for example, named myextmodule.pyd with doc-strings, and

stubgen -p myextmodule -o . --include-docstrings 

pyi file was generate successfully but no doc-strings in it.

Can anyone merge the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @JelleZijlstra@lmbelo@Social-Mean

      Issue actions

        The "include-docstrings" option doesn't work · Issue #16114 · python/mypy