mypy fails to recognize functions as generators when `sys.platform` is used in conditions
オープン
まだ誰も着手していません。
bug
priority-1-normal
topic-runtime-semantics
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
mypy seems to be too thorough when interpreting if sys.platform == ... conditions. Consider the following file:
import sys
from typing import Generator
def f() -> Generator[int, None, None]:
if sys.platform == "darwin":
yield 1
I'm trying to run mypy for this file on Linux using mypy gen.py
Expected behavior:
mypy test passes for this file on Linux
Actual behavior:
I get this on Linux:
$ mypy gen.py
gen.py:4: error: Missing return statement
At the same time, mypy on macOS does not complain. I think that this is related to #698
Platform information:
$ uname -sr; mypy --version; python --version
Linux 4.15.0-34-generic
mypy 0.630
Python 2.7.15rc1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
gen.py の例を使って報告を再現し、Linux で mypy を実行してから、その結果を macOS の挙動と比較します。checker が sys.platform の条件とジェネレーター関数をどのように処理するかを追跡します。Linux で例が return 文の欠落を報告しなくなり、macOS の結果にリグレッションが発生しなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100