python / python/mypy

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

Aperta
#18,859 15 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature topic-configuration
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando il punto di ingresso da riga di comando di Mypy e il percorso esistente che determina il suo stato di uscita dopo la segnalazione degli errori. Aggiungi il comportamento --soft-fail in modo che l’output rimanga invariato mentre il comando termini con 0, quindi verifica l’opzione tramite i test CLI pertinenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.