8000 Don't ignore errors in files passed on the command line by JukkaL · Pull Request #14060 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Don't ignore errors in files passed on the command line #14060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Don't ignore errors in files passed on the command line
that were under a directory in `sys.path`, which sometimes includes
the current working directory, resulting in no errors reported at
all.

Fixes #14042.
  • Loading branch information
JukkaL committed Nov 10, 2022
commit 80f37a33c3d20bb4354064aa1ec3eca579264769
4 changes: 2 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ def __init__(
raise
if follow_imports == "silent":
self.ignore_all = True
elif path and is_silent_import_module(manager, path):
elif path and is_silent_import_module(manager, path) and not root_source:
self.ignore_all = True
self.path = path
if path:
Expand Down Expand Up @@ -2629,7 +2629,7 @@ def find_module_and_diagnose(
else:
skipping_module(manager, caller_line, caller_state, id, result)
raise ModuleNotFound
if is_silent_import_module(manager, result):
if is_silent_import_module(manager, result) and not root_source:
follow_imports = "silent"
return (result, follow_imports)
else:
Expand Down
4 changes: 3 additions & 1 deletion mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
env["PYTHONPATH"] = PREFIX
if os.path.isdir(extra_path):
env["PYTHONPATH"] += os.pathsep + extra_path
cwd = os.path.join(test_temp_dir, custom_cwd or "")
args = [arg.replace("$CWD", os.path.abspath(cwd)) for arg in args]
process = subprocess.Popen(
fixed + args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=os.path.join(test_temp_dir, custom_cwd or ""),
cwd=cwd,
env=env,
)
outb, errb = process.communicate()
Expand Down
65 changes: 65 additions & 0 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -1505,3 +1505,68 @@ def f():
[out]
a.py:2: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs
== Return code: 0

[case testCustomTypeshedDirFilePassedExplicitly]
# cmd: mypy --custom-typeshed-dir dir m.py dir/stdlib/foo.pyi
[file m.py]
1()
[file dir/stdlib/abc.pyi]
1() # Errors are not reported from typeshed by default
[file dir/stdlib/builtins.pyi]
class object: pass
class str(object): pass
class int(object): pass
[file dir/stdlib/sys.pyi]
[file dir/stdlib/types.pyi]
[file dir/stdlib/typing.pyi]
[file dir/stdlib/mypy_extensions.pyi]
[file dir/stdlib/typing_extensions.pyi]
[file dir/stdlib/foo.pyi]
1() # Errors are reported if the file was explicitly passed on the command line
[file dir/stdlib/VERSIONS]
[out]
dir/stdlib/foo.pyi:1: error: "int" not callable
m.py:1: error: "int" not callable

[case testFileInPythonPathPassedExplicitly1]
# cmd: mypy $CWD/pypath/foo.py
[file pypath/foo.py]
1()
[out]
pypath/foo.py:1: error: "int" not callable

[case testFileInPythonPathPassedExplicitly2]
# cmd: mypy pypath/foo.py
[file pypath/foo.py]
1()
[out]
pypath/foo.py:1: error: "int" not callable

[case testFileInPythonPathPassedExplicitly3]
# cmd: mypy -p foo
# cwd: pypath
[file pypath/foo/__init__.py]
1()
[file pypath/foo/m.py]
1()
[out]
foo/m.py:1: error: "int" not callable
foo/__init__.py:1: error: "int" not callable

[case testFileInPythonPathPassedExplicitly4]
# cmd: mypy -m foo
# cwd: pypath
[file pypath/foo.py]
1()
[out]
foo.py:1: error: "int" not callable

[case testFileInPythonPathPassedExplicitly5]
# cmd: mypy -m foo.m
# cwd: pypath
[file pypath/foo/__init__.py]
1() # TODO: Maybe this should generate errors as well? But how would we decide?
[file pypath/foo/m.py]
1()
[out]
foo/m.py:1: error: "int" not callable
0