Spurious error when adding two list
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Mypy reports Unsupported operand types for + when concatenating two lists, when the second operand is a subtype of the first.
This was previously mentioned in this comment in #5492
Below is a simple concise example
To Reproduce
class A:
pass
class B(A):
pass
def foo(a: list[A]) -> None:
pass
l1: list[A] = [A(), B()]
l2: list[B] = [B()]
l3 = l1 + l2
foo(l2 + l1) # OK, no error
foo(l3) # also OK
foo(
l1 + l2
) # ERROR: Unsupported operand types for + ("List[A]" and "List[B]") [operator]mypy(error)
Expected Behavior
No error on the last line
Actual Behavior
Reports spurious error
Your Environment
- Mypy version used: mypy 1.2.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): from pyproject.toml
ignore_missing_imports = true
show_column_numbers = true
warn_redundant_casts = true
warn_unused_ignores = true
warn_unused_configs = true
follow_imports = "normal"
plugins = ["pydantic.mypy"]
- Python version used: 3.10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、簡潔な Python の例を mypy 1.2.0 で実行し、l1 + l2 と l2 + l1 の診断を比較します。issue にはソースファイルもテストパスも記載されていないため、この再現例からリスト加算の型チェック経路をたどってください。完了条件は、最終的な l1 + l2 式で unsupported-operand エラーが発生せず、既存の有効なケースが引き続き有効であることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100