Using syntastic with valid Python 3 code that contains type hints will erroneously give the invalid syntax error.
The solution, according to pyflakes, is to run pyflakes within a Python 3 context, e.g:
$ python3 -m pyflakes foo.py
$ python -m pyflakes foo.py
foo.py:1:12: invalid syntax
def bar(baz: str) -> str:
I do not know how syntatic works with pyflakes, but it is not enough to set
let g:syntastic_python_python_exec = '/usr/bin/python3'
g:syntastic_python_python_exec affects only the python checker. It has nothing to do with the pyflakes checker.
In order to check Python 3 files with the pyflakes checker, you can either:
virtualenv;pyflakes with Python 3, and point g:syntastic_python_pyflakes_exec to it;python3 -m pyflakes and point g:syntastic_python_pyflakes_exec to it;g:syntastic_python_pyflakes_exe (not *_exec) to python3 -m pyflakes:let g:syntastic_python_pyflakes_exe = 'python3 -m pyflakes'
It's up to you to make sure the checker that gets to run actually understands the dialect of the files it's supposed to check.
Thanks for the info.
In my case it still didn't work properly, even after implementing the changes you suggested, since the problem also apparently had to do with pylint. Your comment set me on the right path to fix my environment, though :)
For reference to others who might encounter the same problem as me:
The fault on my part was that I had pylint and flake8 installed only for python2, system-wide. Syntastic fell back to using the python2 pylint and flake8, even with let g:syntastic_python_python_exec = '/usr/bin/python3' set end even when running in a python3 virtualenv.
The following fixed the problem for me:
pip3 install pylint flake8 pyflakes --user
(or installing them in a python3 virtualenv you use so they override any potential user/system-wide python2 pylint/flake8 that may be installed)
Most helpful comment
Thanks for the info.
In my case it still didn't work properly, even after implementing the changes you suggested, since the problem also apparently had to do with pylint. Your comment set me on the right path to fix my environment, though :)
For reference to others who might encounter the same problem as me:
The fault on my part was that I had
pylintandflake8installed only for python2, system-wide. Syntastic fell back to using the python2pylintandflake8, even withlet g:syntastic_python_python_exec = '/usr/bin/python3'set end even when running in a python3 virtualenv.The following fixed the problem for me:
(or installing them in a python3 virtualenv you use so they override any potential user/system-wide python2 pylint/flake8 that may be installed)