Skip to content

Commit c09719c

Browse files
committed
Don't ask to install a stub package if stubs are installed
If we encounter an import of a submodule of a package with installed stubs, and the submodule doesn't exist, don't ask to install stubs since that's not going to help. Also make it possible to ignore this error using `--ignore-missing-imports`. Work on #10645.
1 parent 40dfd7b commit c09719c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mypy/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,13 +2447,14 @@ def find_module_and_diagnose(manager: BuildManager,
24472447
# Don't honor a global (not per-module) ignore_missing_imports
24482448
# setting for modules that used to have bundled stubs, as
24492449
# otherwise updating mypy can silently result in new false
2450-
# negatives.
2450+
# negatives. (Unless there are stubs but they are incomplete.)
24512451
global_ignore_missing_imports = manager.options.ignore_missing_imports
24522452
py_ver = options.python_version[0]
24532453
if ((is_legacy_bundled_package(top_level, py_ver)
24542454
or is_legacy_bundled_package(second_level, py_ver))
24552455
and global_ignore_missing_imports
2456-
and not options.ignore_missing_imports_per_module):
2456+
and not options.ignore_missing_imports_per_module
2457+
and result is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED):
24572458
ignore_missing_imports = False
24582459

24592460
if skip_diagnose:

mypy/modulefinder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ def _find_module_non_stub_helper(self, components: List[str],
232232
plausible_match = True
233233
if (is_legacy_bundled_package(components[0], self.python_major_ver)
234234
or is_legacy_bundled_package('.'.join(components[:2]), self.python_major_ver)):
235-
return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
236-
elif plausible_match:
235+
if (len(components) == 1
236+
or (self.find_module(components[0]) is
237+
ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED)):
238+
return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
239+
if plausible_match:
237240
return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
238241
else:
239242
return ModuleNotFoundReason.NOT_FOUND

0 commit comments

Comments
 (0)