diff --git a/mypy/build.py b/mypy/build.py index 59d46cdf9bb8..3c5f3fc72ac4 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -2443,6 +2443,7 @@ def find_module_and_diagnose(manager: BuildManager, # search path or the module has not been installed. ignore_missing_imports = options.ignore_missing_imports + top_level, second_level = get_top_two_prefixes(file_id) # Don't honor a global (not per-module) ignore_missing_imports # setting for modules that used to have bundled stubs, as @@ -2459,7 +2460,12 @@ def find_module_and_diagnose(manager: BuildManager, if skip_diagnose: raise ModuleNotFound if caller_state: - if not (ignore_missing_imports or in_partial_package(id, manager)): + should_ignore = ( + ignore_missing_imports + or in_partial_package(id, manager) + or (options.ignore_missing_type_hints + and result is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS)) + if not should_ignore: module_not_found(manager, caller_line, caller_state, id, result) raise ModuleNotFound elif root_source: diff --git a/mypy/main.py b/mypy/main.py index 693c7e8c6d13..dee44c452b79 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -476,6 +476,9 @@ def add_invertible_flag(flag: str, imports_group.add_argument( '--ignore-missing-imports', action='store_true', help="Silently ignore imports of missing modules") + imports_group.add_argument( + '--ignore-missing-type-hints', action='store_true', + help="Silently ignore modules missing type hints") imports_group.add_argument( '--follow-imports', choices=['normal', 'silent', 'skip', 'error'], default='normal', help="How to treat imports (default normal)") diff --git a/mypy/options.py b/mypy/options.py index 3eb4809344cf..69df0af879a7 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -41,6 +41,7 @@ class BuildType: "follow_imports_for_stubs", "ignore_errors", "ignore_missing_imports", + "ignore_missing_type_hints", "implicit_reexport", "local_partial_types", "mypyc", @@ -84,6 +85,7 @@ def __init__(self) -> None: self.ignore_missing_imports = False # Is ignore_missing_imports set in a per-module section self.ignore_missing_imports_per_module = False + self.ignore_missing_type_hints = False self.follow_imports = 'normal' # normal|silent|skip|error # Whether to respect the follow_imports setting even for stub files. # Intended to be used for disabling specific stubs.