Mypy ignore_missing_imports in Pyrefly
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.
Mypy configuration
[tool.mypy]
[[tool.mypy.overrides]]
module = ["optional_vendor.*"]
ignore_missing_imports = true
Pyrefly equivalent
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
"*".
Do not confuse the two Pyrefly settings
| 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.
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.
Diagnose before suppressing
An unresolved import is often a misconfigured environment rather than a missing dependency. Check that:
- the dependency is installed in the interpreter Pyrefly queries;
python-interpreter-pathselects the intended environment;- your source roots are listed in
search-path; - custom stubs live in
site-package-path; - the module name matches the package layout.
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.
Example migration
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.