`--warn-unreachable` doesn't flag unnecessary comparison to `None`
オープン
まだ誰も着手していません。
bug
topic-reachability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Here is a full example:
from random import randrange def f(x: int) -> int | None: return None if x == 0 else 2 * x def g(x: int) -> int: return 2 * x if __name__ == '__main__': if f(randrange(10)) is None: print('f: got 0') if g(randrange(10)) is None: # <-- unreachable but not flagged print('g: got 0')
mypy --strict --warn-unreachabledoes not raise any warnings, but it should. So this is a FALSE NEGATIVE bug. Or a new feature, whatever, but in any case this situation should be flagged.
Originally posted by @nickdrozd in #18386
This might be intentional, but I think it's counterintuitive and I can't really see a benefit. Making an issue to make sure I get around to investigating this.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された例を mypy --strict --warn-unreachable で再現し、g を含む比較が報告されないことを確認します。None との比較に対する --warn-unreachable の解析を追跡します。不要な比較が診断され、f を含む到達可能な比較が誤って指摘されなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100