diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index fee484ae02fb..5637931a9ec6 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -553,11 +553,14 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult: return ancestor if approved_stub_package_exists(id): - return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED - elif found_possible_third_party_missing_type_hints: + if len(components) == 1 or ( + self.find_module(components[0]) + is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED + ): + return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED + if found_possible_third_party_missing_type_hints: return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS - else: - return ModuleNotFoundReason.NOT_FOUND + return ModuleNotFoundReason.NOT_FOUND def find_modules_recursive(self, module: str) -> list[BuildSource]: module_path = self.find_module(module, fast_path=True)