From 2c6e729d2b37a2ebe4ba2c69ec2aa79548e2522a Mon Sep 17 00:00:00 2001 From: YingqiDuan <141370165+YingqiDuan@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:27:44 -0700 Subject: [PATCH] Fix command mode with targets set in config --- mypy/main.py | 8 +++++--- test-data/unit/cmdline.test | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index 0cf624a3a5d7b..65b58e52d1470 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -1494,9 +1494,11 @@ def set_strict_flags() -> None: if special_opts.no_executable or options.no_site_packages: options.python_executable = None - # Paths listed in the config file will be ignored if any paths, modules or packages - # are passed on the command line. - if not (special_opts.files or special_opts.packages or special_opts.modules): + # File, package, and module targets from the config file are used only if no target + # is specified on the command line. + if not ( + special_opts.files or special_opts.packages or special_opts.modules or special_opts.command + ): if options.files: special_opts.files = options.files if options.packages: diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 7066034b3e39c..17c0984061279 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -670,6 +670,14 @@ files = config.py mypy: error: Cannot read file 'override.py': No such file or directory == Return code: 2 +[case testCommandOverridesTargetsFromConfig] +# cmd: mypy -c pass +[file mypy.ini] +\[mypy] +files = should_be_ignored.py +packages = should_be_ignored_package +modules = should_be_ignored_module + [case testErrorSummaryOnSuccess] # cmd: mypy --error-summary good.py [file good.py]