Incomplete inference of extracted values from union of tuples
オープン
まだ誰も着手していません。
feature
topic-type-narrowing
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
I expect this is a feature request, though it's possible it indicates a bug.
from typing import Union, Tuple
def func() -> Union[Tuple[None, None], Tuple[int, int]]:
...
a, b = func()
if a:
print(a + b)
if a is not None:
print(a + b)
# Unsupported operand types for + ("int" and "None")
# Right operand is of type "Optional[int]"
Both if tests result in the same behaviour.
Ideally I'd like mypy to know that the test here for a is sufficient to also know that b cannot be None (due to the way that Union works).
Not sure if this is asking too much though.
Python 3.6, mypy 0.770, also master (at 2a3de7b7941f24b6bc53fe0cf8a2b7f8f7fd4e15)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
mypy を使って Python の例を再現し、タプルのユニオンから推論された値に対する 2 つのチェックの診断結果を比較します。タプル・ユニオンの推論に関係する型の絞り込みのエントリーポイントを調査します。両方のチェックで b が int であることが確立され、サポートされていないオペランド型が報告されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100