Should dict() constructor overloads be more permissive?
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 5.1k
- Forks
- 2.1k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 82
Beschreibung
Current constructor overloads are here:
Someone took care to allow specific positive case, and to block specific negative case.
Many potential valid uses have fallen through the cracks:
dict([[1, 2]])
dict("AT TA GC CG".split())
dict([["str", b"bytes"]])
My understanding of the issue is that there's no way to specify sequence length (other than a tuple) in a type hint, that is there's no syntax to hint ["a", "b"] vs ["a", "b", "c"].
This brings a philosophical question: what side should typeshed err on when type hint syntax is not precise enough?
- type whatever Python may accept run time, or
- restrict users to what Python is guaranteed to accept at run time?
It was mentioned at https://github.com/microsoft/pyright/issues/7382 that type checkers trust typeshed, and thus the question belongs here.
My personal preference would be for permissive type hints in these cases.
Beitragsleitfaden
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 mit stdlib/builtins.pyi bei den verlinkten Overloads des dict()-Konstruktors und vergleiche sie mit den Beispielaufrufen im Issue. Prüfe, wie die relevanten Type Checker diese Fälle behandeln, und ermittle anschließend, ob die beabsichtigte Richtlinie darin besteht, breitere zur Laufzeit gültige Eingaben zu akzeptieren; für den Abschluss sind ein abgestimmtes Overload-Design und die entsprechende Validierung erforderlich.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100