python / python/mypy

[stubgen] C++ signature in docstring falsely included in generated stubs

Open
#18,206 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Bug Report

When C/C++ signatures are included in the C modules docstring. It is parsed as an overload.

To Reproduce

This script for examples outputs 2 signatures:

import mypy.stubdoc

sigs = mypy.stubdoc.infer_sig_from_docstring(
    """
addLane(data: MyStruct) -> None

C++: addLane(const MyStruct data) --> void
""",
    "addLane",
)

if sigs is not None:
    for sig in sigs:
        print(sig)

Expected Behavior

There should only be one signature in the resulting stub.

Actual Behavior

there are two signatures produced

FunctionSig(name='addLane', args=[ArgSig(name='data', type='MyStruct', default=False)], ret_type='None')
FunctionSig(name='addLane', args=[ArgSig(name='constMyStructdata', type=None, default=False)], ret_type='void')

Your Environment

  • stubgen version: 1.13.0
  • Python version used: 3.12

I have a pull request to solve this, https://github.com/python/mypy/pull/17658

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with mypy.stubdoc.infer_sig_from_docstring and reproduce the issue using the script in the report. Review pull request #17658 for the existing work and related stubdoc parsing tests. Done means the C++-style line is not emitted as a second signature while the Python signature remains.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.