I'm looking at the doc here:
Is there a way to ignore certain files when making a report? I'm seeing some files I don't want a report of, and I'm wondering if I can make a runtime configuration or somthing to ignore them.
Yes.
You can ignore a whole package (cf this question and the relevant Github issue).
Ignoring just a file was discussed in this GitHub issue which recommended other ways to achieve the same result (@no_type_check
decorator for functions, checking the Python version, custom mypy call script, ...) and was closed as a duplicate of this other issue which happens to have been closed 13 days ago (2021-06-10) by Guido because "it didn't seem all that important", although the PEP 484 states :
A # type: ignore comment on a line by itself at the top of a file, before any docstrings, imports, or other executable code, silences all errors in the file.
In another related GitHub issue, someone mentions there is a command option for exactly that since version 0.810
(2021-02-10) : --exclude (cf commit)
A regular expression that matches file names, directory names and paths which mypy should ignore while recursively discovering files to check. Use forward slashes on all platforms.
Here is my setup :
# file: ok.py
a: int = 4
# file: bad.py
a: int = "definitively not an integer"
with MyPy v0.800
:
$ mypy . --txt-report report0800; cat report0800/index.txt
bad.py:2: error: Incompatible types in assignment (expression has type "str", variable has type "int")
Generated TXT report (via XSLT): /home/stack_overflow/PyCharmProjects/68071098/report0800/index.txt
Found 1 error in 1 file (checked 2 source files)
Mypy Type Check Coverage Summary
================================
Script: index
+-----+-------------------+-------+
| Module | Imprecision | Lines |
+-----+-------------------+-------+
| bad | 0.00% imprecise | 2 LOC |
| ok | 0.00% imprecise | 2 LOC |
+-----+-------------------+-------+
| Total | 0.00% imprecise | 4 LOC |
+-----+-------------------+-------+
with MyPy v0.812
:
$ mypy . --txt-report report0812 --exclude 'bad.py'; cat report0812/index.txt
Generated TXT report (via XSLT): /home/stack_overflow/PyCharmProjects/68071098/report0812/index.txt
Success: no issues found in 1 source file
Mypy Type Check Coverage Summary
================================
Script: index
+----+-------------------+-------+
| Module | Imprecision | Lines |
+----+-------------------+-------+
| ok | 0.00% imprecise | 2 LOC |
+----+-------------------+-------+
| Total | 0.00% imprecise | 2 LOC |
+----+-------------------+-------+
I tried on a real project and the regex behaviour seemed finicky (or maybe I did not understood well the docs), but it worked nonetheless.