python / python/mypy

Improve mypy --pretty output for (multiline) f-strings

Offen
#9,485 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug feature
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Error messages merely say the line number, which is not always accurate - e.g. for multiline strings it's merely the first or last line of the overall multiline string (depending on Python version). If it's a format string and there's dozens of {} elements embedded in it, maybe across hundreds of lines, it can be practically impossible to tell what mypy is referring to. e.g. here's the actual output from a current problem:

     src.py:136: error: "str" has no attribute "expression"  [attr-defined]
     src.py:136: error: Item "str" of "Optional[str]" has no attribute "expression"  [union-attr]
     src.py:136: error: Item "None" of "Optional[str]" has no attribute "expression"  [union-attr]
     src.py:136: error: Item "float" of "Optional[float]" has no attribute "expression"  [union-attr]
     src.py:136: error: Item "None" of "Optional[float]" has no attribute "expression"  [union-attr]
     src.py:136: error: "float" has no attribute "expression"  [attr-defined]
     src.py:136: error: "bool" has no attribute "expression"  [attr-defined]
     src.py:136: error: "int" has no attribute "expression"  [attr-defined]

The multiline string these are embedded in is nearly a hundred lines long and has dozens of embedded elements, almost all of which reference an espression attribute. I genuinely have no idea which ones these messages are referring to. If it at least told me the name of the variable (or whatever), I'd be able to narrow it down.

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

Beginne damit, mypy's --pretty-Darstellung der Diagnosen für Fehler nachzuverfolgen, die in mehrzeiligen f-Strings auftreten; vergleiche die gemeldete Position mit dem eingebetteten Ausdruck, der den Fehler ausgelöst hat. Erledigt ist dies, wenn die Pretty-Ausgabe den relevanten f-String-Ausdruck oder die relevante Variable identifiziert und nicht nur die Zeile des gesamten Strings.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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