Unclear error message: incompatible type "type[str]"; expected "Callable[[_T], _T]"
オープン
まだ誰も着手していません。
topic-usability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
To Reproduce
from collections.abc import Sequence
from typing import TypeVar
_T = TypeVar("_T")
def foo(seq: Sequence[_T]) -> None:
seq = tuple(map(str, seq))
$ mypy ./mypy_bug.py
mypy_bug.py: note: In function "foo":
mypy_bug.py:7:19: error: Argument 1 to "map" has incompatible type "type[str]"; expected "Callable[[_T], _T]"
[arg-type]
seq = tuple(map(str, seq))
^~~
Found 1 error in 1 file (checked 1 source file)
Interestingly enough, this error does not fire if you assign to something other than seq:
def foo(seq: Sequence[_T]) -> None:
not_seq = tuple(map(str, seq)) # no problem, no mypy error
- Mypy version used:
mypy 1.9.0 (compiled: yes) - Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used:
Python 3.12.2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず mypy_bug.py の最小例を mypy で実行し、seq への代入と not_seq への同等の代入を比較します。これら 2 つのコンテキストで、型チェッカーが map の callable 引数をどのように推論するかを追跡します。不整合な診断が解消され、再現ケースにリグレッションテストのカバレッジが追加されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100