python / python/typing

spec: Definition of materialization is insufficient

オープン
#2,027 コメント 2 件 リアクション 4 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic: typing spec
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
8

説明

The spec currently defines materialization as follows:

Given a gradual type A, if we replace zero or more occurrences of Any in A with some type (which can be different for each occurrence of Any), the resulting gradual type B is a materialization of A.

A type A is assignable to B if there exists a pair of materializations A' and B' of A and B such that A' is a subtype of B'.

Now let's consider whether list[int] | list[str] is assignable to list[Any]. To do so, we have to consider materializations of list[Any], created by substituting Any with some other type. But there's nothing we can substitute for Any that would make for a fully static type that is a supertype of list[int] | list[str], since list is invariant in its type parameter. Therefore, list[int] | list[str] is not assignable to list[Any]. Relatedly, this means list[Any] | list[Any] is not equivalent to list[Any]. This is obviously not a desirable conclusion; current type checkers treat list[int] | list[str] as assignable to list[Any], and they should.

I think to fix this, we could say that if A' and A'' are materializations of A, then the union A' | A'' must also be a materialization of A.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされた typing specification の materialization の定義から始め、list[int] | list[str] と list[Any] の例を検討してください。materializations の union は materializations のままであるという提案されたルールを、assignability と equivalence への影響も含めて評価してください。完了の条件は、合意された specification の変更と、更新された説明テキストです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。