python / python/mypy

Wrong column reported for errors in function sig type comments

Offen
#7,893 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug priority-2-low topic-error-reporting topic-usability
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

For the following code



def extract_commit_hash(line):  # type: (str) -> Optional[str]
    ...

def extract_commit_hash2(line):  # type: (str) -> Optional(str)
    ...


mypy reports wrong columns:

image

mypy output:

> mypy --pretty --follow-imports skip --show-column-numbers --show-error-codes wrong-col.py
wrong-col.py:3:10: error: Name 'Optional' is not defined  [name-defined]
    def extract_commit_hash(line):  # type: (str) -> Optional[str]
             ^
wrong-col.py:3:10: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Optional")
wrong-col.py:6:10: error: Invalid type comment or annotation  [valid-type]
    def extract_commit_hash2(line):  # type: (str) -> Optional(str)
             ^
wrong-col.py:6:10: note: Suggestion: use Optional[...] instead of Optional(...)
Found 2 errors in 1 file (checked 1 source file)

From what I found the reported column is always 10 even if the code is more indented.

image

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 gezeigten wrong-col.py-Beispiel und dem mypy-Befehl unter Verwendung von --show-column-numbers. Verfolge, wie Diagnosen für Typkommentare in Funktionssignaturen ihre Spalte berechnen, und überprüfe anschließend, dass Fehler in Funktionen mit unterschiedlicher Einrückung auf die relevante Quellposition statt auf eine feste Spalte verweisen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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