mypy does not catch string formatting errors in `logging.log` that are listed - not interpolated

Offen
#18,794 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
devtools

Rechercherichtung

Beginne damit, die gemeldeten Fälle mit mypy-1.15.0 zu reproduzieren, wobei du dich auf die Einstiegspunkte logging.log und logger.critical konzentrierst und sie mit print vergleichst. Verfolge, wie logging-Aufrufe analysiert werden, und ergänze Tests, sodass eine falsche Anzahl von Formatierungsargumenten gemeldet wird, ohne eine gültige verzögerte Interpolation abzulehnen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

feature

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

Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
Ø Merge
1 T. 18 Std.
Gemergte PRs (30 T.)
54

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/mypy

Alle Issues in python/mypy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.