Skip to content

Commit b55bfe0

Browse files
authored
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.
1 parent 2853e5a commit b55bfe0

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

mypy/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,9 @@ def set_strict_flags() -> None:
853853
if special_opts.no_executable or options.no_site_packages:
854854
options.python_executable = None
855855

856-
# Paths listed in the config file will be ignored if any paths are passed on
857-
# the command line.
858-
if options.files and not special_opts.files:
856+
# Paths listed in the config file will be ignored if any paths, modules or packages
857+
# are passed on the command line.
858+
if options.files and not (special_opts.files or special_opts.packages or special_opts.modules):
859859
special_opts.files = options.files
860860

861861
# Check for invalid argument combinations.

test-data/unit/cmdline.test

+34
Original file line numberDiff line numberDiff line change
@@ -1248,3 +1248,37 @@ x: str = 0
12481248
pkg/x.py:1: error: invalid syntax
12491249
Found 1 error in 1 file (errors prevented further checking)
12501250
== Return code: 2
1251+
1252+
[case testCmdlinePackageAndFile]
1253+
# cmd: mypy -p pkg file
1254+
[out]
1255+
usage: mypy [-h] [-v] [-V] [more options; see below]
1256+
[-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
1257+
mypy: error: May only specify one of: module/package, files, or command.
1258+
== Return code: 2
1259+
1260+
[case testCmdlinePackageAndIniFiles]
1261+
# cmd: mypy -p pkg
1262+
[file mypy.ini]
1263+
\[mypy]
1264+
files=file
1265+
[file pkg.py]
1266+
x = 0 # type: str
1267+
[file file.py]
1268+
y = 0 # type: str
1269+
[out]
1270+
pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
1271+
1272+
1273+
[case testCmdlineModuleAndIniFiles]
1274+
# cmd: mypy -m pkg
1275+
[file mypy.ini]
1276+
\[mypy]
1277+
files=file
1278+
[file pkg.py]
1279+
x = 0 # type: str
1280+
[file file.py]
1281+
y = 0 # type: str
1282+
[out]
1283+
pkg.py:1: error: Incompatible types in assignment (expression has type "int", variable has type "str")
1284+

0 commit comments

Comments
 (0)