Skip to content

Commit 9033bc5

Browse files
Support package and module in config file (#13404)
Closes #10728 Co-authored-by: Shantanu <[email protected]>
1 parent 78706b6 commit 9033bc5

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

docs/source/config_file.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,28 @@ section of the command line docs.
191191

192192
This option may only be set in the global section (``[mypy]``).
193193

194+
.. confval:: modules
195+
196+
:type: comma-separated list of strings
197+
198+
A comma-separated list of packages which should be checked by mypy if none are given on the command
199+
line. Mypy *will not* recursively type check any submodules of the provided
200+
module.
201+
202+
This option may only be set in the global section (``[mypy]``).
203+
204+
205+
.. confval:: packages
206+
207+
:type: comma-separated list of strings
208+
209+
A comma-separated list of packages which should be checked by mypy if none are given on the command
210+
line. Mypy *will* recursively type check any submodules of the provided
211+
package. This flag is identical to :confval:`modules` apart from this
212+
behavior.
213+
214+
This option may only be set in the global section (``[mypy]``).
215+
194216
.. confval:: exclude
195217

196218
:type: regular expression

mypy/config_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def check_follow_imports(choice: str) -> str:
161161
"python_executable": expand_path,
162162
"strict": bool,
163163
"exclude": lambda s: [s.strip()],
164+
"packages": try_split,
165+
"modules": try_split,
164166
}
165167

166168
# Reuse the ini_config_types and overwrite the diff
@@ -178,6 +180,8 @@ def check_follow_imports(choice: str) -> str:
178180
"enable_error_code": lambda s: validate_codes(try_split(s)),
179181
"package_root": try_split,
180182
"exclude": str_or_array_as_list,
183+
"packages": try_split,
184+
"modules": try_split,
181185
}
182186
)
183187

mypy/main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,13 @@ def set_strict_flags() -> None:
12221222

12231223
# Paths listed in the config file will be ignored if any paths, modules or packages
12241224
# are passed on the command line.
1225-
if options.files and not (special_opts.files or special_opts.packages or special_opts.modules):
1226-
special_opts.files = options.files
1225+
if not (special_opts.files or special_opts.packages or special_opts.modules):
1226+
if options.files:
1227+
special_opts.files = options.files
1228+
if options.packages:
1229+
special_opts.packages = options.packages
1230+
if options.modules:
1231+
special_opts.modules = options.modules
12271232

12281233
# Check for invalid argument combinations.
12291234
if require_targets:

mypy/options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ def __init__(self) -> None:
215215
# supports globbing
216216
self.files: list[str] | None = None
217217

218+
# A list of packages for mypy to type check
219+
self.packages: list[str] | None = None
220+
221+
# A list of modules for mypy to type check
222+
self.modules: list[str] | None = None
223+
218224
# Write junit.xml to given file
219225
self.junit_xml: str | None = None
220226

0 commit comments

Comments
 (0)