Skip to content

Commit ba0e9d6

Browse files
Revert to treating exclude in .ini as single string (#11881)
Partially reverts #11329 (with respect to `.ini` documentation). Modifies existing unit tests. Fixes #11830. Co-authored-by: Matthew W <[email protected]>
1 parent 246c9ee commit ba0e9d6

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

docs/source/config_file.rst

+15-5
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,28 @@ section of the command line docs.
197197

198198
.. confval:: exclude
199199

200-
:type: newline separated list of regular expressions
200+
:type: regular expression
201201

202-
A newline list of regular expression that matches file names, directory names and paths
202+
A regular expression that matches file names, directory names and paths
203203
which mypy should ignore while recursively discovering files to check.
204204
Use forward slashes on all platforms.
205205

206206
.. code-block:: ini
207207
208208
[mypy]
209-
exclude =
210-
^file1\.py$
211-
^file2\.py$
209+
exclude = (?x)(
210+
^one\.py$ # files named "one.py"
211+
| two\.pyi$ # or files ending with "two.pyi"
212+
| ^three\. # or files starting with "three."
213+
)
214+
215+
Crafting a single regular expression that excludes multiple files while remaining
216+
human-readable can be a challenge. The above example demonstrates one approach.
217+
``(?x)`` enables the ``VERBOSE`` flag for the subsequent regular expression, which
218+
`ignores most whitespace and supports comments`__. The above is equivalent to:
219+
``(^one\.py$|two\.pyi$|^three\.)``.
220+
221+
.. __: https://docs.python.org/3/library/re.html#re.X
212222

213223
For more details, see :option:`--exclude <mypy --exclude>`.
214224

mypy/config_parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def check_follow_imports(choice: str) -> str:
132132
'cache_dir': expand_path,
133133
'python_executable': expand_path,
134134
'strict': bool,
135-
'exclude': lambda s: [p.strip() for p in s.split('\n') if p.strip()],
135+
'exclude': lambda s: [s.strip()],
136136
}
137137

138138
# Reuse the ini_config_types and overwrite the diff

test-data/unit/cmdline.test

+4-3
Original file line numberDiff line numberDiff line change
@@ -1354,9 +1354,10 @@ b/bpkg.py:1: error: "int" not callable
13541354
# cmd: mypy .
13551355
[file mypy.ini]
13561356
\[mypy]
1357-
exclude =
1358-
abc
1359-
b
1357+
exclude = (?x)(
1358+
^abc/
1359+
|^b/
1360+
)
13601361
[file abc/apkg.py]
13611362
1()
13621363
[file b/bpkg.py]

0 commit comments

Comments
 (0)