FOO and next(iter(FOO))
オープン
まだ誰も着手していません。
bug
topic-type-context
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Python code
FOO = frozenset("abc")
BAR = FOO and next(iter(FOO))
Mypy reports and error
wtf.py:2: error: Argument 1 to "iter" has incompatible type "FrozenSet[str]"; expected "Iterable[FrozenSet[str]]"
Expected Behavior
Ideally, mypy should infer that type of BAR is "falsey or string".
If not that, then "empty set or string".
if not that, then "set or string".
Actual Behavior
mypy seems to be tripped by X op func(X), gets confused 😖
mypy complains about the argument to iter 🤷🏿
Note that expression like BAR = next(iter(FOO)) is understood correctly.
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.9.5
- Operating system and version: macos, universal2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、mypy 0.910 を使って最小限の Python 例を再現し、型チェッカーが iter(FOO) 周辺のブール値 and 式をどのように処理するかを調べます。例で互換性のない引数エラーが報告されなくなり、BAR の推論された型が期待される選択肢のいずれかと一致すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100