Warn about non-optional conditions that don't provide __nonzero__?
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
Maybe mypy should complain about Iterable[...] as an if condition, for example, since it generally doesn't define __nonzero__, so the check is likely unsafe? More generally, we could do this for all classes that don't define __nonzero__, but this could generate too many errors. One option would be to make this an optional check enabled by --strict, at least initially.
Examples:
def f(x: Iterable[int]) -> None:
if not x: # Might never be taken, or at least this could be inconsistently taken
print('x')
class A:
pass # No __nonzero__
def g(a: A) -> None:
if not a: # Similar to above? What if there are subclasses of 'A'?
print('x')
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
The issue names no files, tests, or entry points. Start with the Iterable[int] and class A examples, then review how mypy currently handles conditions and strict-mode checks. Done would require a settled scope for the diagnostic, including subclass behavior and whether it is optional or enabled by --strict.
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
- Da chiarire
- Idoneità per principianti
- 25/100