Type Variable Specialized by Generic
オープン
まだ誰も着手していません。
bug
false-positive
priority-1-normal
topic-type-variables
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
説明
It seems that Type[...] variables dont specialize correctly:
Types = Union[int, str]
T = TypeVar('T', bound=Types)
class A:
x: Types
y: Type[Types]
class B(A, Generic[T]):
x: T # ok
y: Type[T] # error: Incompatible types in assignment
The error that arises is
error: Incompatible types in assignment (expression has type "Type[T]", base class "A" defined the type as "Union[Type[int], Type[str]]")
I believe this is a bug and it should be an allowed specialization (similar to the instance x above), unless there is a counterexample I'm not thinking of?
Tested with mypy v0.660 as well as mypy master + typed-ast master, CPython 3.7.1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python スニペットを再現例として使用し、Type[T] と Union の境界を含むジェネリック属性オーバーライドの型チェックパスを調査してください。mypy が互換性のない代入エラーなしで B の y: Type[T] を受け入れ、この例のリグレッションチェックが追加されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100