Skip to content

Add ignore missing type hints #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
2 changes: 2 additions & 0 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down