Skip to content

Commit

Permalink
Allow packages/modules as args with files in cfg (#9834)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trws committed Jan 6, 2021
1 parent 2853e5a commit b55bfe0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mypy/main.py
Expand Up @@ -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.
Expand Down
34 changes: 34 additions & 0 deletions test-data/unit/cmdline.test
Expand Up @@ -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")

0 comments on commit b55bfe0

Please sign in to comment.