Search code examples
vimvim-pluginpylintpipenvmypy

False import errors running Pylint and MyPy from vim ALE in pipenv. -- :!pylint % works -- :!mypy % works


I have a project directory

project
    - code
        - code.py
    - tests
        - test_code.py

Things have worked in the past with virtualenv. I am now trying pipenv. I have this in my .vimrc

"python with virtualenv support
py << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    activate_this = os.path.join(project_base_dir, 'Scripts/activate_this.py')
    execfile(activate_this, dict(__file__=activate_this))
EOF

That seems to work. I get my virtual environment Python with :!python. I can run :!pylint and :!mypy, neither of which are installed in my global Python.

:!pylint tests\ shows no import errors, but ALE is showing import-error. A similar thing (and worse) happens with mypy. Mypy not only reports false import errors (only when run through ALE), but also misses errors that it catches through :!mypy tests\.

I'm stumped. Any ideas?


Solution

  • There is a setting in ALE:

    let g:ale_python_pylint_change_directory=0
    let g:ale_python_flake8_change_directory=0
    

    If you do not set this, ALE will descend into project subdirectories before linting.