website/docs/migrate/mypy/ignore-missing-imports.mdx
{/*
Mypy's ignore_missing_imports suppresses errors when an imported module cannot
be resolved. In a per-module override the pattern matches the imported
module, not the file that contains the import. Pyrefly's equivalent works the
same way.
[tool.mypy]
[[tool.mypy.overrides]]
module = ["optional_vendor.*"]
ignore_missing_imports = true
ignore-missing-imports = ["optional_vendor.*"]
pyrefly init converts both per-module and global mypy import suppression into
this list. A global ignore_missing_imports = true becomes the module glob
"*".
| Setting | Behavior |
|---|---|
ignore-missing-imports | Substitutes Any only when the matched module cannot be found. If it is found, its real type information is used. |
replace-imports-with-any | Always substitutes Any for the matched module, even when source or stubs are available. |
[errors] missing-import = "ignore" | Suppresses missing-import diagnostics everywhere, rather than for selected modules. |
Prefer ignore-missing-imports for optional dependencies.
replace-imports-with-any is the closer match for mypy's
follow_imports = "skip", and it is a much stronger escape hatch.
:::warning
pyrefly init currently groups follow_imports = "skip" with
ignore_missing_imports, so a migrated skip rule lands in
ignore-missing-imports and keeps type information for modules that do resolve.
Inspect the generated list and move entries to replace-imports-with-any where
you need mypy's unconditional skip behavior.
:::
An unresolved import is often a misconfigured environment rather than a missing dependency. Check that:
python-interpreter-path selects the intended environment;search-path;site-package-path;If the module resolves from the command line but not in the IDE, or the other way round, the two are using different configs or different interpreters.
Mypy:
[mypy]
mypy_path = src
[mypy-vendor_sdk.*]
ignore_missing_imports = True
Pyrefly:
search-path = ["src"]
ignore-missing-imports = ["vendor_sdk.*"]
Pyrefly supports mypy's module name pattern syntax; see Module Globbing for the exact matching rules.