Finals and Literals: Spec contradiction
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beschreibung
This came up in python/typeshed#16301. I assume this is mostly a clerical/historical error, but let me know if we should follow the whole spec change process.
The typing spec says about Final:
Example:
ID: Final = 1The typechecker should apply its usual type inference mechanisms to determine the type of ID (here, likely, int).
And then a bit later:
Type checkers should treat uses of a final name that was initialized with a literal as if it was replaced by the literal.
Both sentences are copied directly from PEP 591, which overlapped with the Literals PEP 586.
I assume that we should change the first sentence to "here, likely, Literal[1]" and change the second sentence to be a bit more concrete along these lines:
Type checkers should infer uses of a final name that was initialized with a literal
XasLiteral[X]ifXis an allowed literal type (cf. to the literals section). Otherwise, they should infer the type of theX.
(And maybe extend the example after a bit.)
In fact, this is what the conformance tests already check:
(Although the tests could be extended a bit.)
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Syntax von Final und die Formulierung zur Verwendung von Literalen in der typing specification mit PEP 591 und PEP 586 zu vergleichen. Überprüfe conformance/tests/qualifiers_final_annotation.py, insbesondere die Zeilen 11-13, und erweitere die relevanten Fälle bei Bedarf. Als erledigt gilt die Aufgabe, wenn die Spezifikation intern konsistent ist und die conformance tests das präzisierte Verhalten widerspiegeln.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- documentation, testing-qa
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 72/100