Platform check is not remembered after `return`
オープン
まだ誰も着手していません。
feature
topic-type-narrowing
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
A platform check that is working fine in if and else is not working after if ... return.
To Reproduce
import sys
def works() -> None:
if sys.platform != "win32":
return
else:
from winreg import REG_SZ
def fails() -> None:
if sys.platform != "win32":
return
from winreg import REG_SZ
https://mypy-play.net/?mypy=latest&python=3.11&gist=eddad091a6082bd85c5c7524839726b1
Expected Behavior
No error.
Actual Behavior
main.py:12: error: Module "winreg" has no attribute "REG_SZ" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Failure is on Linux
- Mypy version used: 1.1.1
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.11.2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python リプロデューサーと mypy-play リンクから始め、プラットフォームチェックと早期リターンが型の絞り込みにどのように影響するかを追跡します。if/else のケースと if ... return のケースを比較します。完了条件は、後者の形式で winreg.REG_SZ の誤った属性エラーが報告されなくなることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100