MCPcopy Index your code
hub / github.com/python/mypy / module_not_found

Function module_not_found

mypy/build.py:3915–3981  ·  view source on GitHub ↗
(
    manager: BuildManager,
    line: int,
    caller_state: State,
    target: str,
    reason: ModuleNotFoundReason,
)

Source from the content-addressed store, hash-verified

3913
3914
3915def module_not_found(
3916 manager: BuildManager,
3917 line: int,
3918 caller_state: State,
3919 target: str,
3920 reason: ModuleNotFoundReason,
3921) -> None:
3922 errors = manager.errors
3923 save_import_context = errors.import_context()
3924 errors.set_import_context(caller_state.import_context)
3925 errors.set_file(caller_state.xpath, caller_state.id, caller_state.options)
3926 errors.set_file_ignored_lines(
3927 caller_state.xpath,
3928 caller_state.tree.ignored_lines if caller_state.tree else caller_state.imports_ignored,
3929 caller_state.ignore_all or caller_state.options.ignore_errors,
3930 )
3931 if target == "builtins":
3932 manager.error(
3933 line, 'Cannot find "builtins" module. Typeshed appears broken!', blocker=True
3934 )
3935 errors.raise_error()
3936 else:
3937 daemon = manager.options.fine_grained_incremental
3938 msg, notes = reason.error_message_templates(daemon)
3939 if reason == ModuleNotFoundReason.NOT_FOUND:
3940 code = codes.IMPORT_NOT_FOUND
3941 elif (
3942 reason == ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS
3943 or reason == ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
3944 ):
3945 code = codes.IMPORT_UNTYPED
3946 else:
3947 code = codes.IMPORT
3948 manager.error(line, msg.format(module=target), code=code)
3949
3950 if (
3951 reason == ModuleNotFoundReason.NOT_FOUND
3952 and not errors.prefer_simple_messages()
3953 and errors.is_error_code_enabled(code)
3954 and line not in errors.ignored_lines.get(caller_state.xpath, {})
3955 ):
3956 top_level_target = target.split(".")[0]
3957 if not top_level_target.startswith("_"):
3958 known_modules = get_known_modules(
3959 manager.find_module_cache.stdlib_py_versions, manager.options.python_version
3960 )
3961 matches = best_matches(top_level_target, known_modules, n=3)
3962 matches = [m for m in matches if m.lower() != top_level_target.lower()]
3963 if matches:
3964 errors.report(
3965 line,
3966 0,
3967 f'Did you mean {pretty_seq(matches, "or")}?',
3968 severity="note",
3969 code=code,
3970 )
3971
3972 dist = stub_distribution_name(target)

Callers 1

find_module_and_diagnoseFunction · 0.85

Calls 15

get_known_modulesFunction · 0.90
best_matchesFunction · 0.90
pretty_seqFunction · 0.90
stub_distribution_nameFunction · 0.90
import_contextMethod · 0.80
set_import_contextMethod · 0.80
set_fileMethod · 0.80
raise_errorMethod · 0.80
is_error_code_enabledMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…