Copy with slicing of a list[subclass] should be ok for list[superclass]
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
-
Are you reporting a bug, or opening a feature request?
As I expected this to work, I assume it is a bug. -
Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
from typing import List
class Upi(object):
pass
class Subi(Upi):
pass
subs = [Subi(), Subi()]
ok1:List[Upi] = [s for s in subs]
ok2:List[Upi] = list(subs)
notOk:List[Upi] = subs[:] # this should also be ok IMHO
-
What is the actual behavior/output?
notOk list is not ok for mypy. -
What is the behavior/output you expect?
Should be ok. Actually saw this in a function return value so should be ok there also when function is returning list of superclass things. -
What are the versions of mypy and Python you are using?
mypy 0.720, Python 3.7.3 -
What are the mypy flags you are using? (For example --strict-optional)
None
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue では実装ファイルもテストも指定されていません。まず提供された再現ケースを mypy で実行し、その後、リストのスライシングが内包表記や list(subs) と比較してどのように型付けされるかを追跡してください。完了条件は、subs[:] から List[Upi] への代入が flags なしで受け入れられ、報告されたケースのカバレッジがあることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100