warn-unreachable false-positive when method updates attribute after assert
オープン
まだ誰も着手していません。
bug
topic-reachability
topic-type-narrowing
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
Consider the following code:
from dataclasses import dataclass
@dataclass
class Foo:
value: int
modified: bool = False
def update(self) -> None:
self.value += 1
self.modified = True
foo = Foo(42)
assert not foo.modified
foo.update()
assert foo.modified
print("Reached")
When this is run, the print("Reached") line is reached, but mypy doesn't seem to realize that. Running mypy --warn-unreachable --pretty on the above code gives:
unreachable03.py:18: error: Statement is unreachable
print("Reached")
^
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: both v0.931 and the GitHub version as of commit 48d810d5ed25f898d4f220a7476b6b267c289b9a
- Mypy command-line flags:
--warn-unreachable --pretty - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.9
- Operating system and version: macOS 11.6
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された dataclass の例を mypy --warn-unreachable --pretty で使って報告を再現し、2つのアサーションと foo.update() の周辺で行われる到達不能コードの解析を追跡してください。この例の回帰テストを追加し、print("Reached") が到達不能として報告されなくなったことを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100