Allow ignore to be on any line of multi-line statement
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Feature
Currently, comments can be added to a line to ignore either all errors (# type: ignore), or a specific error code (eg. # type: ignore[call-arg]). When a single statement spans multiple lines, the comment has to be added on the line that mypy "decides" is the one with the error (is it the first line of the expression, rather than first line of the statement?). In some cases, it would make sense to allow the comment to be on a different line of the same statement. I propose allowing it to be on any line of the statement, and therefore to apply to the whole statement.
Pitch
Sometimes it makes more sense for it to be another line, such as when importing something that mypy thinks does not exist, it makes sense to have the ignore on the same line as the attribute that is reported as not existing.
from typing import ( # ignore currently needs to be here
Union,
DoesNotExist, # type: ignore[error attr-defined]
)
Sometimes, a formatter like black changes a long line into a multiple line statement. The comment that was at the end of the line is moved to the end of the last line.
def foo(bar:int) -> str: ...
def baz() -> int: ...
a = ( # type: ignore[call-arg]
"something"
if baz() > 0 else
foo() # ignore currently needs to be here
) # formatters (eg. black) often put ignore here
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den zwei mehrzeiligen Beispielen und der verknüpften mypy-play-Reproduktion; verfolge, wie mypy type: ignore-Kommentare Anweisungen zuordnet. Fertig ist die Arbeit, wenn ein Ignore in jeder beliebigen Zeile einer mehrzeiligen Anweisung den relevanten Fehler dieser Anweisung unterdrückt, einschließlich spezifischer Codes, ohne das Verhalten für separate Anweisungen zu ändern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100