@overload declarations in stubs - required to be directly adjacent?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Bug Report
Currently, mypy requires @overload declarations in stubs to be directly adjacent, with no declarations (e.g. type vars) in between. However, I don't find that requirement in PEP 484 [1], nor in the typing module documentation [2].
[1] https://www.python.org/dev/peps/pep-0484/#function-method-overloading
[2] https://docs.python.org/3/library/typing.html#typing.overload
To Reproduce
Consider the following type stub:
import typing
@typing.overload
def foo() -> None: ...
K = typing.TypeVar('K')
@typing.overload
def foo(k: K) -> K: ...
Then run stubtest on it.
Expected Behavior
According to the documentation, I would expect this stub to be valid.
Actual Behavior
$ python -m mypy.stubtest teststub
error: failed mypy build.
teststub.pyi:4: error: Single overload definition, multiple required
teststub.pyi:8: error: Name 'foo' already defined on line 4
teststub.pyi:8: error: Single overload definition, multiple required
Pulling the type var declaration up fixes it:
import typing
K = typing.TypeVar('K')
@typing.overload
def foo() -> None: ...
@typing.overload
def foo(k: K) -> K: ...
Your Environment
Python 3.7.1 (anaconda) on Linux, latest master of mypy.
I also tested with mypy 0.790 on Windows, with the same result.
$ python --version
Python 3.7.1
$ python -m mypy --version
mypy 0.820+dev.497556f466dcda90d850b23e86c55ec4082be3f5
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、示されている teststub と python -m mypy.stubtest teststub を使って失敗を再現します。mypy が隣接する @typing.overload 宣言をどのように検証しているかを追跡し、間にある TypeVar を対象とする回帰テストを追加します。stub が受け入れられ、既存の overload の診断が引き続き正しいことを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100