Ray's Knowledge Base
Unlock

Judge a # type: ignore under every way mypy is run before turning on warn_unused_ignores

PitfallVerified 2 Oct 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

warn_unused_ignores flagged import dftracer.dftracer as profiler # type: ignore as Unused "type: ignore" comment [unused-ignore] under the Makefile command (which passes --ignore-missing-imports), with or without torch or the wheel files. Removing it broke a plain mypy run and editor mypy plugins, which then reported a missing import. The other 7 flagged ignores (x = None on names mypy treats as Any) were truly unused.

Cause#

make type-check passed --ignore-missing-imports but pyproject.toml did not set it, so the same ignore was needed under one invocation and unused under another.

Fix#

The fix that works with the flag and covers every invocation is a per-module override in pyproject.toml: [[tool.mypy.overrides]] with module = ["dftracer.dftracer", "dftracer.dftracer_dbg"] and ignore_missing_imports = true. Test old and new code with plain mypy and with the Makefile flags, and with pyright if editors use it.

Evidence#

pydftracer; the per-module override satisfied every invocation.

Also found by searching

  • Unused "type: ignore" comment [unused-ignore]
  • warn_unused_ignores flagged an ignore that a plain mypy run needs
  • --ignore-missing-imports only in the Makefile, not in pyproject.toml
  • removing a type ignore broke editor mypy with a missing import