Skip to content

Commit 5e92478

Browse files
implement import-untyped-stubs-available
1 parent 050632b commit 5e92478

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

docs/source/running_mypy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ the second time to type check your code properly after mypy has
400400
installed the stubs. It also can make controlling stub versions harder,
401401
resulting in less reproducible type checking — it might even install
402402
incompatible versions of your project's non-type dependencies, if the
403-
type stubs require them!
403+
type stubs require them!
404404

405405
By default, :option:`--install-types <mypy --install-types>` shows a confirmation prompt.
406406
Use :option:`--non-interactive <mypy --non-interactive>` to install all suggested

mypy/build.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2780,11 +2780,10 @@ def module_not_found(
27802780
msg, notes = reason.error_message_templates(daemon)
27812781
if reason == ModuleNotFoundReason.NOT_FOUND:
27822782
code = codes.IMPORT_NOT_FOUND
2783-
elif (
2784-
reason == ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
2785-
or reason == ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
2786-
):
2783+
elif reason == ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
27872784
code = codes.IMPORT_UNTYPED
2785+
elif reason == ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED:
2786+
code = codes.IMPORT_UNTYPED_STUBS_AVAILABLE
27882787
else:
27892788
code = codes.IMPORT
27902789
errors.report(line, 0, msg.format(module=target), code=code)

mypy/errorcodes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def __init__(
3434
sub_code_map[sub_code_of.code].add(code)
3535
error_codes[code] = self
3636

37+
def is_import_related_code(self) -> bool:
38+
return IMPORT in (self.code, self.sub_code_of)
39+
3740
def __str__(self) -> str:
3841
return f"<ErrorCode {self.code}>"
3942

@@ -114,7 +117,10 @@ def __hash__(self) -> int:
114117
"import-untyped", "Require that imported module has stubs", "General", sub_code_of=IMPORT
115118
)
116119
IMPORT_UNTYPED_STUBS_AVAILABLE: Final = ErrorCode(
117-
"import-untyped-stubs-available", "Require that imported module (with known stubs) has stubs", "General", sub_code_of=IMPORT
120+
"import-untyped-stubs-available",
121+
"Require that imported module (with known stubs) has stubs",
122+
"General",
123+
sub_code_of=IMPORT,
118124
)
119125
NO_REDEF: Final = ErrorCode("no-redef", "Check that each name is defined once", "General")
120126
FUNC_RETURNS_VALUE: Final = ErrorCode(

mypy/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from mypy import errorcodes as codes
1212
from mypy.error_formatter import ErrorFormatter
13-
from mypy.errorcodes import IMPORT, IMPORT_NOT_FOUND, IMPORT_UNTYPED, ErrorCode, mypy_error_codes
13+
from mypy.errorcodes import ErrorCode, mypy_error_codes
1414
from mypy.options import Options
1515
from mypy.scope import Scope
1616
from mypy.util import DEFAULT_SOURCE_OFFSET, is_typeshed_file
@@ -476,7 +476,7 @@ def _add_error_info(self, file: str, info: ErrorInfo) -> None:
476476
self.error_info_map[file].append(info)
477477
if info.blocker:
478478
self.has_blockers.add(file)
479-
if info.code in (IMPORT, IMPORT_UNTYPED, IMPORT_NOT_FOUND):
479+
if info.code is not None and info.code.is_import_related_code():
480480
self.seen_import_error = True
481481

482482
def _filter_error(self, file: str, info: ErrorInfo) -> bool:
@@ -522,7 +522,7 @@ def add_error_info(self, info: ErrorInfo) -> None:
522522
self.only_once_messages.add(info.message)
523523
if (
524524
self.seen_import_error
525-
and info.code not in (IMPORT, IMPORT_UNTYPED, IMPORT_NOT_FOUND)
525+
and (info.code is None or (not info.code.is_import_related_code()))
526526
and self.has_many_errors()
527527
):
528528
# Missing stubs can easily cause thousands of errors about

0 commit comments

Comments
 (0)