Generate a JSON report from your mypy output
Project description
Mypy JSON Report
A JSON report of your mypy output that helps you push towards full type coverage of your project.
Quickstart
Install with pip.
pip install mypy-json-report
Pipe the output of mypy through the mypy-json-report
CLI app.
Store the output to a file, and commit it to your git repo.
mypy . --strict | mypy-json-report parse --output-file mypy-ratchet.json
git add mypy-ratchet.json
git commit -m "Add mypy errors ratchet file"
Now you have a snapshot of the mypy errors in your project. Compare against this file when making changes to your project to catch regressions and improvements.
Example output
If mypy was showing you errors like this:
example.py:8: error: Function is missing a return type annotation
example.py:8: note: Use "-> None" if function does not return a value
example.py:58: error: Call to untyped function "main" in typed context
example.py:69: error: Call to untyped function "main" in typed context
Found 3 errors in 1 file (checked 3 source files)
Then the report would look like this:
{
"example.py": {
"Call to untyped function \"main\" in typed context": 2,
"Function is missing a return type annotation": 1
}
}
Errors are grouped by file. To reduce churn, the line on which the errors occur is removed and repeated errors are counted.
Ratchet file
The --diff-old-report FILENAME
flag serves two purposes.
-
It prints new (and adjacent, and similar) errors to STDERR. This is useful for seeing what errors need to be fixed before committing.
-
It will error when the ratchet file doesn't match the new report. This is helpful for catching uncommitted changes in CI.
Example usage
You could create a GitHub Action to catch regressions (or improvements).
---
name: Mypy check
on: [push]
jobs:
build:
runs-on: ubuntu-latest
mypy:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install Python dependencies
run: |
pip install mypy mypy-json-report
- name: Run mypy
run: |
mypy . --strict | mypy-json-report parse --diff-old-report mypy-ratchet.json --output-file mypy-ratchet.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mypy_json_report-1.2.0.tar.gz
.
File metadata
- Download URL: mypy_json_report-1.2.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e1486617caf746fde1818d58cdf060968d1db5173a50456d2e76803a0c2bd17 |
|
MD5 | e7bca3a676effb55338cc0c6de33a076 |
|
BLAKE2b-256 | 3175dbe801c0119d38b0f8b2c9ac5beebc8d553ed92bb1edf73bbf3bef21fcf4 |
File details
Details for the file mypy_json_report-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: mypy_json_report-1.2.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44977105067354b9d79dd07e30677daeb7641ac87a58048aa2f0d2b9172f1be4 |
|
MD5 | 90b2e6e36483c1af1abbfac1149ae19b |
|
BLAKE2b-256 | 3b0a9b08df3e632ae190bf7812782dba7067148404bc4f3ce22e9ce2f0aef762 |