python / python/mypy

Add --soft-fail option to capture Mypy output without blocking CI

Offen
#18,859 15 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

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

Beschreibung

Feature

Add a --soft-fail option to Mypy that allows capturing its output without causing a hard failure in CI/CD pipelines.

Pitch

Currently, Mypy exits with a 1 status code when type errors are found, which is expected behavior. However, in many CI/CD pipelines (especially those integrating with SonarQube or similar tools), it's useful to capture all Mypy output while still allowing the pipeline to continue in a controlled way.

A --soft-fail option would:

  • Allow Mypy to run normally and produce full output, including errors and warnings.
  • Exit with status code 0 so that CI/CD jobs don’t automatically fail.
  • Still allow external tools like SonarQube to analyze and report issues without interfering with the pipeline’s flow.

I currently have a one liner workaround in tox:

https://gist.github.com/balihb/0b64435c0e8f553791071cea4a897c91

[tox]
min_version = 4.20
envlist =
# renovate: datasource=docker depName=python
    3.13

[testenv]
skip_install = true
pass_env =
    FORCE_COLOR
    MYPY_*
    NO_COLOR
    PIP_*
    PYTHONUNBUFFERED
    PY_COLORS
    TERM
deps =
    -r requirements.txt
    -r requirements-mypy.txt
commands =
commands =
    python -c "import os, re, shlex, subprocess, sys; \
    from pathlib import Path; \
    result = subprocess.run(['mypy'] + shlex.split('{posargs:src}'), check=False, text=True, capture_output=True); \
    result.stdout.strip() and sys.stdout.write(result.stdout); \
    result.stderr.strip() and sys.stderr.write(result.stderr); \
    output = Path(os.getenv('MYPY_TOX_OUTPUT', default='.report/mypy/output.txt')); \
    output.parent.mkdir(parents=True, exist_ok=True); \
    output.write_text(re.compile(r'\x1b\\[[0-9;]*?m').sub('', result.stdout)); \
    sys.exit(1 if result.returncode == 2 else 0)"

but this is far from ideal.

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, Mypys Kommandozeilen-Einstiegspunkt und den bestehenden Pfad nachzuverfolgen, der nach der Fehlerausgabe den Exit-Status bestimmt. Füge das Verhalten von --soft-fail hinzu, sodass die Ausgabe unverändert bleibt, während der Befehl mit 0 beendet wird, und überprüfe die Option anhand der entsprechenden CLI-Tests.

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
45/100

Neue Issues direkt in Ihr Postfach

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