Add --soft-fail option to capture Mypy output without blocking CI
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Mypy’s command-line entry point and the existing path that determines its exit status after reporting errors. Add the --soft-fail behavior so output remains unchanged while the command exits 0, and verify the option through the relevant CLI tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100