list.append seems to break return type checker
オープン
まだ誰も着手していません。
bug
priority-1-normal
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Hello, concerning the function below:
from typing import List
def foo() -> List[int]:
listings = None
if 2 != 2:
listings = list()
listings.append(1)
return listings
I expected:
Incompatible return value type (got "Optional[List[int]]", expected "List[int]")
I got no error
This one does throw the expected error (same config):
from typing import List
def foo() -> List[int]:
listings = None
if 2 != 2:
listings = [1]
return listings
running mypy 0.770 on python 3.8
I would appreciate it if you could tell me if I am doing something wrong :)
Have a good day !
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Python 3.8 上で mypy 0.770 を使って 2 つのスニペットを再現し、return 前の listings の推論された型を比較してください。list.append とリストリテラルの処理を追跡し、その後、両方のケースで戻り値に対して期待される Optional[List[int]] エラーが発生することを示す回帰テストを追加してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100