Optional strict checking of *args and/or multiple assignment
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
Currently mypy does optimistic checking of *args -- we don't generate error if it could be valid. This seems like a reasonable default, since it avoids false positive errors. However, some users might prefer stricter checking as an option. When this option is enabled, mypy would only allow variable-length (non-Any) *args in a call if the callee also accepts *args.
Example:
def f(a: int) -> None: pass
x = [1, 2]
f(*x) # Currently accepted, since mypy doesn't know the length of x
PR #7392 relaxed the rules so that we assume that any list *args argument could be empty and thus we don't complain about even if a caller *args argument is only valid when it's empty.
Similarly this option (or a similar option) could reject variable-length rvalues in multiple assignment like this:
x = [1, 2]
a, b, c = x # Currently accepted
If we'd have support for enabling/disabling specific error codes, these checks could easily be implemented through error codes that are disabled by default.
Refactoring code such as the above (if correct) to pass mypy could be somewhat painful, however. It could be written like this:
def f(a: int, b: int) -> None: pass
def g(x: List[int]) -> None:
assert len(x) == 2
f(x[0], x[1])
(Of course, a # type: ignore would also work.)
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
Non sono indicati file sorgente o test. Inizia esaminando PR #7392 e la gestione esistente degli argomenti di lunghezza variabile con *args e delle assegnazioni multiple; il lavoro sarebbe completato quando sarà stato definito un design opzionale per i controlli rigorosi di questi casi, incluso come abilitare i controlli.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Da chiarire
- Idoneità per principianti
- 25/100