python / python/mypy

Cannot ignore type errors in multiline strings

Offen
#9,484 12 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-type-ignore
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

stringy = "foo"

f"""\
{stringy.nope()}
"""  # type: ignore

(ignore that this is a true positive - my real code is much more complicated and is actually valid, the above is just a contrived example to show the core problem)

In Python 3.7 with mypy 0.782, it reports the error on the closing """ (if you remove the # type: ignore), so it picks up the ignore directive and all is well. In Python 3.8, it reports the error on the previous line. There's no way to add # type: ignore on that line, and adding it anywhere else has no effect.

In other cases it tends to report the error as being on the line with the opening """… I'm not sure why in this particular, contrived example it behaves differently. But either way, it's a major problem, since there's no practical workaround for this [in my much larger, real-world code]. It's blocking the upgrade to Python 3.8 for one of my major projects.

(the output from mypy w/ Python 3.8)

test.py:4: error: "str" has no attribute "nope"
Found 1 error in 1 file (checked 1 source file)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere den Bericht mit dem bereitgestellten test.py-Snippet unter Verwendung von Python 3.8 und mypy 0.782 und vergleiche anschließend die Diagnoseposition mit Python 3.7. Verfolge die Diagnosen für mehrzeilige f-Strings und die Behandlung von # type: ignore; abgeschlossen ist die Aufgabe, wenn das Ignore an der abschließenden dreifach in Anführungszeichen gesetzten Zeichenkette den gemeldeten Fehler konsistent unterdrückt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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