Disallow assignment of `Any` to known/explicit types and/or Introduce `Unknown` type
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
I'd like an option that prevents assigned of the Any type to something with a known type, in particular places where I've specified the type.
Returns:
def return_type_a() -> TypeA:
untyped = {}
return untype # Disallow
Assignement:
store : Dict[StoreRef,StoreItem = {}
def create() -> Dict:
return {}
store = create() # Disallow
Pitch
It'd be nice to have a stricter boundary between typed and untyped code. The samples I show above are frequent sources of error for me and they quietly slip by the type checking.
While migrated code there are still a lot of Any's in the code, and in some domains they'll never go away (when dealing with genuinely generic data structures, also now since some recrusive types, like JSON, need to use Any).
Related
An explicit Unknown type, in contrast to Any, would also help a lot. TypeScript has an unknown and it is helpful for dealing with generic data and not accidentally using it as the wrong type.
If an Unknown was available the above could also be achieved by turning on the "disallow any" flags and using Unknown in places where generic data is needed.
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 damit, mypy's Umgang mit Any und seine vorhandenen disallow-any flags zu lesen, wobei die Rückgabe- und Zuweisungsbeispiele als Verhaltensfälle dienen. Kläre, ob die Arbeit strengere Zuweisungsprüfungen, einen Unknown-Typ oder beides umfasst; als abgeschlossen gilt sie, wenn das ausgewählte Verhalten spezifiziert und durchgesetzt ist, ohne die legitime Verwendung generischer Daten zu beeinträchtigen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100