bug inferring signatures from docstrings in stubgenc
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Bug Report
When generating stubs from c modules, stubgen uses mypy.stubdoc to parse signatures from docstrings, if they are present, however, this does not work if the function takes no arguments
To Reproduce
Function with args:
>>> from mypy.stubdoc import infer_sig_from_docstring
>>> infer_sig_from_docstring('func(x) -> int', 'func')
[FunctionSig(name='func', args=[ArgSig(name='x', type=None, default=False)], ret_type='int')]
Function without args:
>>>: infer_sig_from_docstring('func() -> int', 'func')
[] # <--- no signature!!!!
The fact that no signatures are returned means that the stubs that are generated look like this:
def func(*args, **kwargs) -> Any
...
But given that we have a docstring with a valid signature, the stubs should look like this:
def func() -> int
...
This seems like a bug. I'll make a PR to fix this when I have some time.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with mypy.stubdoc.infer_sig_from_docstring and reproduce the two examples from the issue, then trace how stubgen uses the returned signatures. Done means a no-argument docstring such as func() -> int yields a signature and stubgen produces the corresponding typed function stub instead of an *args/**kwargs fallback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100