Skip to content

Commit

Permalink
rename STUBS_NOT_INSTALLED to APPROVED_STUBS_NOT_INSTALLED (#10558)
Browse files Browse the repository at this point in the history
Since this code path involves mypy recommending installation of a stub
package, I thought I'd rename the enum to make it slightly clearer
that this should only be triggered for packages we know to be good.

Linking #10538

Co-authored-by: hauntsaninja <>
  • Loading branch information
hauntsaninja committed May 30, 2021
1 parent d57d5d1 commit 0635422
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mypy/build.py
Expand Up @@ -2555,7 +2555,7 @@ def module_not_found(manager: BuildManager, line: int, caller_state: State,
if '{stub_dist}' in note:
note = note.format(stub_dist=legacy_bundled_packages[top_level])
errors.report(line, 0, note, severity='note', only_once=True, code=codes.IMPORT)
if reason is ModuleNotFoundReason.STUBS_NOT_INSTALLED:
if reason is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
manager.missing_stub_packages.add(legacy_bundled_packages[top_level])
errors.set_import_context(save_import_context)

Expand Down
10 changes: 5 additions & 5 deletions mypy/modulefinder.py
Expand Up @@ -57,7 +57,7 @@ class ModuleNotFoundReason(Enum):
WRONG_WORKING_DIRECTORY = 2

# Stub PyPI package (typically types-pkgname) known to exist but not installed.
STUBS_NOT_INSTALLED = 3
APPROVED_STUBS_NOT_INSTALLED = 3

def error_message_templates(self, daemon: bool) -> Tuple[str, List[str]]:
doc_link = "See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports"
Expand All @@ -71,7 +71,7 @@ def error_message_templates(self, daemon: bool) -> Tuple[str, List[str]]:
elif self is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
msg = 'Skipping analyzing "{module}": found module but no type hints or library stubs'
notes = [doc_link]
elif self is ModuleNotFoundReason.STUBS_NOT_INSTALLED:
elif self is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
msg = (
'Library stubs not installed for "{module}" (or incompatible with Python {pyver})'
)
Expand Down Expand Up @@ -231,7 +231,7 @@ def _find_module_non_stub_helper(self, components: List[str],
or self.fscache.isfile(dir_path + ".py")):
plausible_match = True
if components[0] in legacy_bundled_packages:
return ModuleNotFoundReason.STUBS_NOT_INSTALLED
return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
elif plausible_match:
return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
else:
Expand Down Expand Up @@ -311,7 +311,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
if isinstance(non_stub_match, ModuleNotFoundReason):
if non_stub_match is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
found_possible_third_party_missing_type_hints = True
elif non_stub_match is ModuleNotFoundReason.STUBS_NOT_INSTALLED:
elif non_stub_match is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
need_installed_stubs = True
else:
third_party_inline_dirs.append(non_stub_match)
Expand Down Expand Up @@ -413,7 +413,7 @@ def _find_module(self, id: str, use_typeshed: bool) -> ModuleSearchResult:
return ancestor

if need_installed_stubs:
return ModuleNotFoundReason.STUBS_NOT_INSTALLED
return ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
elif found_possible_third_party_missing_type_hints:
return ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
else:
Expand Down

0 comments on commit 0635422

Please sign in to comment.