Skip to content

Commit

Permalink
Support package and module in config file (#13404)
Browse files Browse the repository at this point in the history
Closes #10728

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
  • Loading branch information
sameer-here and hauntsaninja committed Oct 4, 2022
1 parent 78706b6 commit 9033bc5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
22 changes: 22 additions & 0 deletions docs/source/config_file.rst
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
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
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
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

0 comments on commit 9033bc5

Please sign in to comment.