1

I'm trying to run mypy type hints and just get a lot of errors for external libraries.

I've checked this topic in the docs

and have a mypy.ini like this:

# Global options:

[mypy]
python_version = 3.8
; warn_return_any = True
; warn_unused_configs = True

# Per-module options:

[httplib2]
ignore_missing_imports = True

[google.cloud]
ignore_missing_imports = True

but when I run mypy it still fills the console with these errors. And, ironically, doesn't find any deliberate errors in my own code.

(venv) dcollier@dcsan:~/dev/kzen$ mypy cxutils/digger/chat_stat.py 
cxutils/gbot.py:11: error: Skipping analyzing 'httplib2': found module but no type hints or library stubs
cxutils/logit.py:10: error: Skipping analyzing 'google.cloud': found module but no type hints or library stubs
cxutils/logit.py:12: error: Skipping analyzing 'ansimarkup': found module but no type hints or library stubs
cxutils/biglib.py:18: error: Skipping analyzing 'pandas_gbq': found module but no type hints or library stubs

... etc

I'm using mypy in a virtualenv and which mypy confirms this.

dcsan
  • 11,333
  • 15
  • 77
  • 118
  • 1
    The syntax is `[mypy-httplib2]`. Alternatively, you can edit your code so it reads `import httplib2 # type ignore`. – Tim Roberts Jun 05 '21 at 21:55
  • thanks! so every import should be prefixed with `[mypy-...` ? – dcsan Aug 04 '21 at 21:59
  • Yes. And by the way, I learned this by reading the documentation, which you could have done as well. https://mypy.readthedocs.io/en/stable/config_file.html – Tim Roberts Aug 04 '21 at 23:23
  • i linked to the docs above but misread from the examples. thanks so much for pointing that out, I will rtfm again next time! – dcsan Aug 04 '21 at 23:34

1 Answers1

0

You can fix this by prepending each module with mypy-, like this:

...

[mypy-httplib2]
ignore_missing_imports = True

[mypy-google.cloud]
ignore_missing_imports = True

Or you can use the pyproject.toml file with the following content instead of the mypy.ini file:

[[tool.mypy.overrides]]
module = [
    "httplib2",
    "google.cloud",
]
ignore_missing_imports = true

BTW, pyproject.toml allows you to configure additional tools besides the mypy (e.g. isort). Also, note the syntax differences of .toml & .ini files.

Airat K
  • 55
  • 1
  • 1
  • 10