diff --git a/docs/source/config_file.rst b/docs/source/config_file.rst index 60d0137c5506..abaec31c6888 100644 --- a/docs/source/config_file.rst +++ b/docs/source/config_file.rst @@ -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 diff --git a/mypy/config_parser.py b/mypy/config_parser.py index 52f8182220c1..be690ee78fbc 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -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 @@ -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, } ) diff --git a/mypy/main.py b/mypy/main.py index 1074a9ac70d8..e8be9f0d01fe 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -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: diff --git a/mypy/options.py b/mypy/options.py index 76df064842f2..1910f9532913 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -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