7

I am running Mypy v0.910 with pre-commit. It complains that python-dateutil does not have type stubs. However, even after installing the stubs, I get the same error.

My pre-commit config is

default_language_version:
  python: python3
repos:
  <other hooks>
  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.910
    hooks:
      - id: mypy
        args:
            - --install-types
        additional_dependencies: [tokenize-rt==3.2.0]

When I try to commit, it complains that the stubs are not there and then fails to install them.

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

coordinator/policy.py:5: error: Library stubs not installed for "dateutil.parser" (or incompatible with Python 3.7)
coordinator/policy.py:5: note: Hint: "python3 -m pip install types-python-dateutil"
coordinator/policy.py:5: note: (or run "mypy --install-types" to install all missing stub packages)
tests/test_policy.py:6: error: Cannot find implementation or library stub for module named "pyhocon"
coordinator/configuration.py:4: error: Cannot find implementation or library stub for module named "pyhocon"
coordinator/configuration.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 3 errors in 3 files (checked 7 source files)

Installing missing stub packages:
/Users/me/.cache/pre-commit/repov_smpwjv/py_env-python3/bin/python -m pip install types-python-dateutil

Install? [yN] Traceback (most recent call last):
  File "/Users/me/.cache/pre-commit/repov_smpwjv/py_env-python3/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/Users/me/.cache/pre-commit/repov_smpwjv/py_env-python3/lib/python3.7/site-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 120, in main
  File "mypy/main.py", line 1161, in install_types
EOFError: EOF when reading a line

There appears to be an open issue related to this on python-dateutil: https://github.com/dateutil/dateutil/issues/383

Is there a way to tell Mypy not to worry about the missing stubs? At the moment, the only workaround that I can think of is to completely disable Mypy.

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
Troy Daniels
  • 3,270
  • 2
  • 25
  • 57

2 Answers2

3

This issue still exits on the latest mypy hook 0.971

This is the hook that causes the problem

  - hooks:
      - description: Type checking for Python
        exclude: tests/.*$
        id: mypy
    repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.971

The only way I have been able to solve it is by modifying the hook above as

  - hooks:
      - additional_dependencies: [types-python-dateutil==2.8.19]
        description: Type checking for Python
        exclude: tests/.*$
        id: mypy
    repo: https://github.com/pre-commit/mirrors-mypy
    rev: v0.971

When run locally as poetry run mypy src, you still need to add types-python-dateutil as a dev dependency

PirateApp
  • 5,433
  • 4
  • 57
  • 90
0

It seems as per the below link that from version 0.931 of mypy this does not happen: https://github.com/python/mypy/issues/11920