Disallow assignment of `Any` to known/explicit types and/or Introduce `Unknown` type
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia leggendo la gestione di Any da parte di mypy e i suoi flag disallow-any esistenti, usando gli esempi di restituzione e assegnazione come casi comportamentali. Chiarisci se il lavoro comprende controlli di assegnazione più rigidi, un tipo Unknown o entrambi; il lavoro è completo quando il comportamento selezionato è specificato e applicato senza compromettere l'uso legittimo di dati generici.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100