(🎁) No warning about `TypeAlias` to bare `TypeVar` when using `TypeAlias`
オープン
まだ誰も着手していません。
feature
priority-2-low
topic-runtime-semantics
topic-type-alias
topic-type-variables
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
from typing import TypeVar, TypeAlias
T = TypeVar("T")
TAlias: TypeAlias = T
def foo(
t1: TAlias[int], # no error
t2: TAlias, # error: Missing type parameters for generic type "TAlias"
) -> None: ...
Treating it as a generic type and not as TypeVar is incorrect as at runtime it is not subscriptable:
Traceback (most recent call last):
File "test.py", line 7, in <module>
t1: TAlias[int], # no error
TypeError: 'TypeVar' object is not subscriptable
Strangely, the correct error is reported when the TypeAlias is omitted.
from typing import TypeVar, TypeAlias
T = TypeVar("T")
TAlias = T # error: Type variable "__main__.T" is invalid as target for type alias [misc]
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている test.py の再現例から始め、mypy master、Python 3.10、strict flags を使って playground の設定と比較します。TypeAlias 形式が TAlias[int] を受け入れる一方で、直接のエイリアスが無効な TypeVar ターゲットを報告する理由を追跡します。完了条件は、エイリアス形式が適切な診断を出力し、無効な添字付きの使用を受け入れないことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100