Skip to content

Support package and module in config file #13404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 4, 2022
22 changes: 22 additions & 0 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ section of the command line docs.

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

.. confval:: modules

:type: comma-separated list of strings

A comma-separated list of packages which should be checked by mypy if none are given on the command
line. Mypy *will not* recursively type check any submodules of the provided
module.

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


.. confval:: packages

:type: comma-separated list of strings

A comma-separated list of packages which should be checked by mypy if none are given on the command
line. Mypy *will* recursively type check any submodules of the provided
package. This flag is identical to :confval:`modules` apart from this
behavior.

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

.. confval:: exclude

:type: regular expression
Expand Down
4 changes: 4 additions & 0 deletions mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def check_follow_imports(choice: str) -> str:
"python_executable": expand_path,
"strict": bool,
"exclude": lambda s: [s.strip()],
"packages": try_split,
"modules": try_split,
}

# Reuse the ini_config_types and overwrite the diff
Expand All @@ -178,6 +180,8 @@ def check_follow_imports(choice: str) -> str:
"enable_error_code": lambda s: validate_codes(try_split(s)),
"package_root": try_split,
"exclude": str_or_array_as_list,
"packages": try_split,
"modules": try_split,
}
)

Expand Down
9 changes: 7 additions & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,13 @@ def set_strict_flags() -> None:

# Paths listed in the config file will be ignored if any paths, modules or packages
# are passed on the command line.
if options.files and not (special_opts.files or special_opts.packages or special_opts.modules):
special_opts.files = options.files
if not (special_opts.files or special_opts.packages or special_opts.modules):
if options.files:
special_opts.files = options.files
if options.packages:
special_opts.packages = options.packages
if options.modules:
special_opts.modules = options.modules

# Check for invalid argument combinations.
if require_targets:
Expand Down
6 changes: 6 additions & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ def __init__(self) -> None:
# supports globbing
self.files: list[str] | None = None

# A list of packages for mypy to type check
self.packages: list[str] | None = None

# A list of modules for mypy to type check
self.modules: list[str] | None = None

# Write junit.xml to given file
self.junit_xml: str | None = None

Expand Down