`tuple[*Ts]` subtype with extra type parameter not gradually assignable to itself
オープン
まだ誰も着手していません。
bug
topic-pep-646
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
This demonstrates the issue:
from typing import Any
class Array[DataT, *ShapeTs](tuple[*ShapeTs]): ...
type Float2D = Array[float, *tuple[int, int]] # or Array[float, int, int]
type FloatND = Array[float, *tuple[Any, ...]]
def from_2d(a: Float2D) -> FloatND:
return a # mypy: ✅, pyright: ✅
def into_2d(a: FloatND) -> Float2D:
return a # mypy: ❌, pyright: ✅
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=1b95c702df6de35fa3f61aa7b5dfef16
Without the additional DataT typar, the false positive disappears
from typing import Any
class Array[*ShapeTs](tuple[*ShapeTs]): ...
type Float2D = Array[*tuple[int, int]] # or Array[int, int]
type FloatND = Array[*tuple[Any, ...]]
def from_2d(a: Float2D) -> FloatND:
return a # mypy: ✅, pyright: ✅
def into_2d(a: FloatND) -> Float2D:
return a # mypy: ✅, pyright: ✅
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=be0dfedeb0e7ed14da359cd52d2901e7
The issue also disappears when tuple is no longer a base class
from typing import Any
class Array[float, *ShapeTs]: ...
type Float2D = Array[float, *tuple[int, int]] # or Array[float, int, int]
type FloatND = Array[float, *tuple[Any, ...]]
def from_2d(a: Float2D) -> FloatND:
return a # mypy: ✅, pyright: ✅
def into_2d(a: FloatND) -> Float2D:
return a # mypy: ✅, pyright: ✅
https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=a1439e7c3037239bc4663b981534fb17
Potentially related issues:
- #18665
- #19106
- #19109
- #19110
- #19860
- #19858
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされている mypy-play の例にある 2 つの Python の再現コードを mypy 3.13 strict settings で実行し、from_2d と into_2d の代入、および DataT なしまたは tuple の基底クラスなしのバリエーションを比較します。関連する issue #18665、#19106、#19109、#19110、#19860、#19858 を確認します。問題のある代入が一貫して処理され、すでに通っているケースを壊さないことを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100