python / python/typing

spec: Definition of materialization is insufficient

Aperta
#2,027 2 commenti 4 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

topic: typing spec
Lingua principale
Python
Stelle
1.8k
Fork
302
Merge medio
23h
PR unite (30g)
8

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalla definizione di materialization nella typing specification collegata e analizza l’esempio list[int] | list[str] rispetto a list[Any]. Valuta la regola proposta secondo cui le unioni di materializations rimangono materializations, compreso il suo effetto su assignability ed equivalence; il lavoro sarà completato quando saranno disponibili una modifica concordata della specification e un testo esplicativo aggiornato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
documentation
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.