spec: Definition of materialization is insufficient

Offen
#2,027 2 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Anfängerfreundlichkeit
38/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
python
Bereich
documentation

Rechercherichtung

Beginne mit der Definition von materialization in der verlinkten typing specification und arbeite das Beispiel list[int] | list[str] gegenüber list[Any] durch. Bewerte die vorgeschlagene Regel, dass Unions von materializations materializations bleiben, einschließlich ihrer Auswirkungen auf assignability und equivalence; als abgeschlossen gilt die Aufgabe, wenn eine abgestimmte Änderung der specification und aktualisierter erklärender Text vorliegen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

topic: typing spec

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.

Vorherrschende Sprache
Python
Sterne
1.8k
Forks
302
Ø Merge
23 Std.
Gemergte PRs (30 T.)
8

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/typing

Alle Issues in python/typing

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.