__contains__ is not reconize as a None check
オープン
まだ誰も着手していません。
bug
topic-type-narrowing
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
I am struggling a bit on making mypy validate the type of an Iterable containing Optional:
def func_1(address: Address) -> Optional[float] :
...
def func_2(addresses: Tuple[Addresses, ...]) -> Optional[Tuple[float, ...]]:
ordered_tuple = tuple(
func_1(address)
for address in addresses)
return ordered_tuple if not None in ordered_tuple else None
Mypy seems to do not recognize the check if not None in ordered_tuple else None.
A workaround that I found is to check all the values returned by func_1 :
def func_1(address: Address) -> Optional[float] :
...
def func_2(addresses: Tuple[Addresses, ...]) -> Optional[Tuple[float, ...]]:
ordered_list = []
for address in addresses:
value = func_1(address)
if value is not None:
ordered_list.append(value)
else:
return None
return tuple(ordered_list)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue にはファイルもテストも指定されていません。まず mypy で 2 つの例を再現し、None in ordered_tuple に対する型チェックの動作を調べてください。最初のバージョンが、意図した Optional から non-Optional なタプルへの絞り込みを伴って受け入れられ、既存の workaround も引き続き有効であれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 32/100