Skip to content
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

Silence errors from third party packages in daemon #13768

Merged
merged 4 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 13 additions & 5 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,8 @@ def __init__(
raise
if follow_imports == "silent":
self.ignore_all = True
elif path and is_silent_import_module(manager, path):
self.ignore_all = True
self.path = path
if path:
self.abspath = os.path.abspath(path)
Expand Down Expand Up @@ -2613,11 +2615,8 @@ def find_module_and_diagnose(
else:
skipping_module(manager, caller_line, caller_state, id, result)
raise ModuleNotFound
if not manager.options.no_silence_site_packages:
for dir in manager.search_paths.package_path + manager.search_paths.typeshed_path:
if is_sub_path(result, dir):
# Silence errors in site-package dirs and typeshed
follow_imports = "silent"
if is_silent_import_module(manager, result):
follow_imports = "silent"
return (result, follow_imports)
else:
# Could not find a module. Typically the reason is a
Expand Down Expand Up @@ -3560,3 +3559,12 @@ def record_missing_stub_packages(cache_dir: str, missing_stub_packages: set[str]
else:
if os.path.isfile(fnam):
os.remove(fnam)


def is_silent_import_module(manager: BuildManager, path: str) -> bool:
if not manager.options.no_silence_site_packages:
for dir in manager.search_paths.package_path + manager.search_paths.typeshed_path:
if is_sub_path(path, dir):
# Silence errors in site-package dirs and typeshed
return True
return False
5 changes: 3 additions & 2 deletions mypy/server/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,10 @@ def key(node: FineGrainedDeferredNode) -> int:

nodes = sorted(nodeset, key=key)

options = graph[module_id].options
state = graph[module_id]
options = state.options
manager.errors.set_file_ignored_lines(
file_node.path, file_node.ignored_lines, options.ignore_errors
file_node.path, file_node.ignored_lines, options.ignore_errors or state.ignore_all
)

targets = set()
Expand Down
38 changes: 38 additions & 0 deletions test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -2206,3 +2206,41 @@ a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missin
a.py:1: error: Library stubs not installed for "jack"
a.py:1: note: Hint: "python3 -m pip install types-JACK-Client"
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

[case testIgnoreErrorsFromTypeshed]
# flags: --custom-typeshed-dir tmp/ts --follow-imports=normal
# cmd1: mypy a.py
# cmd2: mypy a.py

[file a.py]
import foobar

[file ts/stdlib/abc.pyi]
[file ts/stdlib/builtins.pyi]
class object: pass
class str: pass
class ellipsis: pass
[file ts/stdlib/sys.pyi]
[file ts/stdlib/types.pyi]
[file ts/stdlib/typing.pyi]
def cast(x): ...
[file ts/stdlib/typing_extensions.pyi]
[file ts/stdlib/VERSIONS]
[file ts/stubs/mypy_extensions/mypy_extensions.pyi]

[file ts/stdlib/foobar.pyi.2]
# We report no errors from typeshed. It would be better to test ignoring
# errors from PEP 561 packages, but it's harder to test and uses the
# same code paths, so we are using typeshed instead.
import baz
import zar
undefined

[file ts/stdlib/baz.pyi.2]
import whatever
undefined

[out]
a.py:1: error: Cannot find implementation or library stub for module named "foobar"
a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
==