python / python/mypy

bug inferring signatures from docstrings in stubgenc

オープン
#11,092 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug topic-stubgen
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

mypy.stubdoc.infer_sig_from_docstring から始めて、issue の 2 つの例を再現し、その後、stubgen が返されたシグネチャをどのように使うかを追跡します。func() -> int のような引数なしの docstring がシグネチャを生成し、stubgen が *args/**kwargs フォールバックではなく、対応する型付き関数スタブを生成すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。