Skip to content
Latchkey

mypy "error: Module has no attribute" in CI

mypy resolved the module but its type information does not declare the attribute you accessed. The runtime may work, but the stubs or the installed version mypy sees do not expose the name, so it reports [attr-defined].

What this error means

mypy fails CI with "error: Module 'X' has no attribute 'Y' [attr-defined]" even though the code runs fine.

python
app/client.py:8: error: Module "httpx" has no attribute "AsyncClientX"  [attr-defined]
Found 1 error in 1 file (checked 12 source files)

Common causes

A version skew between runtime and what mypy resolved

mypy type-checks against the installed package; if CI installed a version where the name does not exist (or is not re-exported), it flags it.

Missing or incomplete type stubs

A package without inline types relies on stub packages; if the stub omits the attribute, mypy cannot see it.

How to fix it

Align versions and stubs

  1. Confirm the package version mypy resolves matches what the code targets.
  2. Install the matching stub package if the library is untyped.
  3. Re-run mypy to confirm the attribute is now known.
Terminal
pip install "httpx==0.27.*" types-requests

Narrow the ignore if the runtime is correct

When the attribute genuinely exists at runtime but stubs lag, suppress just that line rather than disabling the check.

app/client.py
client = httpx.AsyncClientX()  # type: ignore[attr-defined]

How to prevent it

  • Pin the same versions for runtime and type checking.
  • Install stub packages for untyped dependencies.
  • Prefer targeted # type: ignore[code] over broad suppression.

Frequently asked questions

What causes "mypy "Module has no attribute""?
mypy type-checks against the installed package; if CI installed a version where the name does not exist (or is not re-exported), it flags it.
How do I fix mypy "Module has no attribute"?
Align versions and stubs

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card