constrained TypeVar and star operator incompatible type
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
We can't use TypeVar with star operator, maybe I wrongly used TypeVar.
Thanks
To Reproduce
T = TypeVar("T", str, int)
def test(a: Sequence[T]) -> list[T]:
return [*a]
Expected Behavior
No error
Actual Behavior
cactus.py: note: In function "test":
cactus.py:57:14: error: List item 0 has incompatible type "Sequence[T]"; expected "str" [list-item]
return [*a]
^
cactus.py:57:14: error: List item 0 has incompatible type "Sequence[T]"; expected "int" [list-item]
return [*a]
^
cactus.py:57:14: note: See https://mypy.rtfd.io/en/stable/_refs.html#code-list-item for more info
Your Environment
- Mypy version used: 1.11.1
- Python version used: 3.12.1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue の Python reproducer から始め、mypy 1.11.1 と Python 3.12.1 を使用して、制約付き TypeVar とスター式に対する互換性のないリスト項目エラーを確認します。この式の型チェック経路を追跡し、例がエラーなしで通るようにしてから、reproducer を再実行して期待される動作を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100