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 modules in site-packages and typeshed #5303

Merged
merged 7 commits into from Jul 6, 2018

Silence typeshed and simplify implementation

  • Loading branch information...
ethanhs committed Jul 3, 2018
commit c5b3697bd301340ab073313d7f786dfd83edb969
Copy path View file
@@ -1820,7 +1820,7 @@ def __init__(self,
if not path and source is None:
assert id is not None
try:
path, follow_imports, self.ignore_all = find_module_and_diagnose(
path, follow_imports = find_module_and_diagnose(
manager, id, self.options, caller_state, caller_line,
ancestor_for, root_source, skip_diagnose=temporary)
except ModuleNotFound:
@@ -2307,7 +2307,7 @@ def find_module_and_diagnose(manager: BuildManager,
caller_line: int = 0,
ancestor_for: 'Optional[State]' = None,
root_source: bool = False,
skip_diagnose: bool = False) -> Tuple[str, str, bool]:
skip_diagnose: bool = False) -> Tuple[str, str]:
"""Find a module by name, respecting follow_imports and producing diagnostics.
If the module is not found, then the ModuleNotFound exception is raised.
@@ -2328,7 +2328,6 @@ def find_module_and_diagnose(manager: BuildManager,
Returns a tuple containing (file path, target's effective follow_imports setting)
"""
ignore_all = False
file_id = id
if id == 'builtins' and options.python_version[0] == 2:
# The __builtin__ module is called internally by mypy
@@ -2343,11 +2342,6 @@ def find_module_and_diagnose(manager: BuildManager,
path = manager.find_module_cache.find_module(file_id, manager.search_paths,
manager.options.python_executable)
if path:
if os.path.isabs(path):
for dir in manager.search_paths.package_path:
if commonpath([dir, path]) == dir:
# Silence errors in site-package dirs
ignore_all = True
# For non-stubs, look at options.follow_imports:
# - normal (default) -> fully analyze
# - silent -> analyze but silence errors
@@ -2374,8 +2368,12 @@ def find_module_and_diagnose(manager: BuildManager,
skipping_module(manager, caller_line, caller_state,
id, path)
raise ModuleNotFound

return (path, follow_imports, ignore_all)
if os.path.isabs(path):
for dir in manager.search_paths.package_path + manager.search_paths.typeshed_path:
if commonpath([dir, path]) == dir:
# Silence errors in site-package dirs and typeshed
follow_imports = 'silent'
return (path, follow_imports)
else:
# Could not find a module. Typically the reason is a
# misspelled module name, missing stub, module not in
@@ -762,7 +762,6 @@ main:1: error: Cannot find module named 'a'
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
==
a.py:3: error: Name 'z' is not defined
<ROOT>/test-data/unit/lib-stub/broken.pyi:2: error: Name 'y' is not defined

[case testRenameModule]
import a
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.