python / python/mypy

emit a warning for "unused Any"

Aperta
#20,078 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature topic-disallow-any
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

A common problem afflicting novices getting into python static type annotations is that they assume Any is the top type in Python, like how Never is its bottom type. Hence, they use Any too much, where it is not necessary.

I think we should emit a warning when an explicit Any annotation is used but didn't have to be, much like what we do for warn-redundant-casts.

In fact, I think there are three related warnings we should emit:

  1. If Any is used but object would have worked
  2. If Any is used but mypy was able to deduce a type that worked (using the regular mypy deduction)
  3. If there is a Callable special form with ... (Ellipsis) in place of the list of parameter types (basically just another way to spell Any, see https://typing.python.org/en/latest/spec/callables.html#meaning-of-in-callable) but one of the previous two cases holds

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando il comportamento esistente di mypy per warn-redundant-casts e la semantica dei puntini di sospensione di Callable nella specifica di typing. Il lavoro è completo quando mypy è in grado di distinguere i tre casi proposti: Any non necessario quando object è sufficiente, Any quando l’inferenza fornisce un tipo utilizzabile e la forma Callable corrispondente, con avvisi per ogni caso applicabile.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
compilers, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.