From a22f88d399cc40cf31c88586b61220964be4dd2f Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 23 Dec 2020 13:43:48 -0800 Subject: [PATCH 1/2] allow packages/modules as args with files in cfg 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 efd356747271..b8c0738b09a6 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -851,9 +851,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..07990972b123 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: str = 0 +[file file.py] +y: str = 0 +[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: str = 0 +[file file.py] +y: str = 0 +[out] +pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") + From b28d2cfb9e6ed65923e9d1856038b5198e347b18 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Wed, 23 Dec 2020 14:17:30 -0800 Subject: [PATCH 2/2] use comment syntax for pack/mod + file tests This should solve the python version issue in the initial commit. --- test-data/unit/cmdline.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test-data/unit/cmdline.test b/test-data/unit/cmdline.test index 07990972b123..8fe9f478a077 100644 --- a/test-data/unit/cmdline.test +++ b/test-data/unit/cmdline.test @@ -1263,9 +1263,9 @@ mypy: error: May only specify one of: module/package, files, or command. \[mypy] files=file [file pkg.py] -x: str = 0 +x = 0 # type: str [file file.py] -y: str = 0 +y = 0 # type: str [out] pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str") @@ -1276,9 +1276,9 @@ pkg.py:1: error: Incompatible types in assignment (expression has type "int", va \[mypy] files=file [file pkg.py] -x: str = 0 +x = 0 # type: str [file file.py] -y: str = 0 +y = 0 # type: str [out] pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")