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

Don't ask to install a stub package if stubs are installed #10670

Merged
merged 3 commits into from Jun 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions mypy/build.py
Expand Up @@ -2447,13 +2447,14 @@ def find_module_and_diagnose(manager: BuildManager,
# Don't honor a global (not per-module) ignore_missing_imports
# setting for modules that used to have bundled stubs, as
# otherwise updating mypy can silently result in new false
# negatives.
# negatives. (Unless there are stubs but they are incomplete.)
global_ignore_missing_imports = manager.options.ignore_missing_imports
py_ver = options.python_version[0]
if ((is_legacy_bundled_package(top_level, py_ver)
or is_legacy_bundled_package(second_level, py_ver))
and global_ignore_missing_imports
and not options.ignore_missing_imports_per_module):
and not options.ignore_missing_imports_per_module
and result is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED):
ignore_missing_imports = False

if skip_diagnose:
Expand Down
10 changes: 7 additions & 3 deletions mypy/modulefinder.py
Expand Up @@ -230,10 +230,14 @@ def _find_module_non_stub_helper(self, components: List[str],
elif not plausible_match and (self.fscache.isdir(dir_path)
or self.fscache.isfile(dir_path + ".py")):
plausible_match = True
if (is_legacy_bundled_package(components[0], self.python_major_ver)
or is_legacy_bundled_package('.'.join(components[:2]), self.python_major_ver)):
if is_legacy_bundled_package(components[0], self.python_major_ver):
if (len(components) == 1
or (self.find_module(components[0]) is
ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED)):
return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
if is_legacy_bundled_package('.'.join(components[:2]), self.python_major_ver):
return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
elif plausible_match:
if plausible_match:
return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
else:
return ModuleNotFoundReason.NOT_FOUND
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-modules.test
Expand Up @@ -3107,3 +3107,18 @@ from google.cloud import x
main:1: error: Cannot find implementation or library stub for module named "google.cloud"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:1: error: Cannot find implementation or library stub for module named "google"

[case testMissingSubmoduleOfInstalledStubPackage]
import bleach.xyz
from bleach.abc import fgh
[file bleach/__init__.pyi]
[out]
main:1: error: Cannot find implementation or library stub for module named "bleach.xyz"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
main:2: error: Cannot find implementation or library stub for module named "bleach.abc"

[case testMissingSubmoduleOfInstalledStubPackageIgnored]
# flags: --ignore-missing-imports
import bleach.xyz
from bleach.abc import fgh
[file bleach/__init__.pyi]