From b55bfe0796ddf6236bc21b46a48c6b961372fe79 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 6 Jan 2021 07:49:19 -0800 Subject: [PATCH] Allow packages/modules as args with files in cfg (#9834) Currently only files can be specified on the command line if files are specified in mypy.ini. This looks a great deal like a bug, especially since packages and modules cannot be specified in the configuration file. This commit changes the logic to only use the files from the ini file if none of (modules/packages/files) are specified on the command line and adds tests to verify the new behavior. --- mypy/main.py | 6 +++--- test-data/unit/cmdline.test | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/mypy/main.py b/mypy/main.py index d701c57aff97..ab38f7478b3f 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -853,9 +853,9 @@ 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 are passed on - # the command line. - if options.files and not special_opts.files: + # 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 # Check for invalid argument combinations. diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 6fe3d4ecbcaf..8fe9f478a077 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -1248,3 +1248,37 @@ x: str = 0 pkg/x.py:1: error: invalid syntax Found 1 error in 1 file (errors prevented further checking) == Return code: 2 + +[case testCmdlinePackageAndFile] +# cmd: mypy -p pkg file +[out] +usage: mypy [-h] [-v] [-V] [more options; see below] + [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...] +mypy: error: May only specify one of: module/package, files, or command. +== Return code: 2 + +[case testCmdlinePackageAndIniFiles] +# cmd: mypy -p pkg +[file mypy.ini] +\[mypy] +files=file +[file pkg.py] +x = 0 # type: str +[file file.py] +y = 0 # type: str +[out] +pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") + + +[case testCmdlineModuleAndIniFiles] +# cmd: mypy -m pkg +[file mypy.ini] +\[mypy] +files=file +[file pkg.py] +x = 0 # type: str +[file file.py] +y = 0 # type: str +[out] +pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") +