python / python/mypy

Support 'on'/'off' for type ignores

Offen
#9,483 4 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

Sometimes it's impossible to put # type: ignore on the offending line - e.g. because it's a multiline string, and there's nowhere you can put the comment outside the string that mypy will recognise. Or more generally, there might be a whole block of code for which mypy has a bunch of spurious complaints, so putting in dozens of # type: ignores is a bit noisy.

The only other option today is to have mypy ignore the entire file, but that has nasty ramifications - beyond just killing type checking for what might be 99% checkable, it also makes any imports of that file invalid, and so you have to spread ignore directives out like a messy spiderweb.

Thus, it'd be great if one could do e.g. # type: ignore on and # type: ignore off, so that the scope could be controlled precisely.

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

Das Issue nennt keine Dateien, Tests oder Einstiegspunkte. Beginne damit nachzuverfolgen, wie mypy derzeit # type: ignore-Direktiven parst und anwendet, und bestimme dann, wie on und off Diagnosen über mehrzeilige Zeichenketten und Codeblöcke hinweg begrenzen sollen. Erledigt ist die Aufgabe, wenn bereichsbezogene Ignores funktionieren, ohne die Prüfung für den Rest der Datei zu deaktivieren oder Importe ungültig zu machen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
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.