mypy does not catch string formatting errors in `logging.log` that are listed - not interpolated
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
I could not find the same issue previously reported here, but these concepts are so generic I would not be surprised user-error is the cause of my failed earch.
Bug Report
In the following script, mypy correctly identifies a string formatting error in case B, which uses print
Cases E and F will both raise exceptions and are not caught.
To Reproduce
import logging
log = logging.getLogger(__name__)
a = "1"
b = "2"
print("print.passes A (%s) %s" % (a, b))
try:
print("print.fail B [mypy catches] (%s) %s" % (a, ))
except TypeError:
pass
log.critical("log.passes C (%s) %s" % (a, b))
log.critical("log.passes D (%s) %s" , a, b)
log.critical("log.fail E (%s) %s" , (a, b))
log.critical("log.fail F (%s) %s" , a)
Expected Behavior
I expected mypy to catch the string formatting error here.
I understand logging.log works differently and delays the interpolation. it would be nice if mypy could catch the number of arguments passed to logging to hint at a possible error or pass
Actual Behavior
mypy does not catch this
Your Environment
mypy-1.15.0
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 riproducendo i casi segnalati con mypy-1.15.0, concentrandoti sui punti di ingresso logging.log e logger.critical e confrontandoli con print. Traccia il modo in cui vengono analizzate le chiamate a logging, quindi aggiungi la copertura necessaria affinché vengano segnalati conteggi errati degli argomenti di formattazione senza rifiutare un’interpolazione ritardata valida.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100