FinnM
FinnM

Reputation: 411

Vim pymode throws "invalid syntax" error on async function definition

I'm currently developing some async python in vim and have pymode installed as a plugin. But I'm having an issue with file linting because the linter gets hung up on the first (and valid) async definition and won't lint the rest of the file.

@user_bp.get('/api/v1/user')
async def get_users(request): # `invalid syntax` error on 'async', linting stops here
    with scoped_session() as session:
        statement = User.__table__.select()
        users = [dict(user) for user in session.execute(statement)]

    return json(users)

# ... many lines of unlinted code

My vimrc has the language set to python3 and syntax checker to pep8, but this still cant seem to shake the error.

" ~/.vim/ftplugin/python.vim

setlocal shiftwidth=4
setlocal tabstop=4
setlocal softtabstop=4
setlocal smarttab

" PYMODE : enable
let g:pymode = 1
let g:pymode_python = 'python3'


" PYMODE : disable the following
let g:pymode_virtualenv = 0
let g:pymode_folding = 0
let g:pymode_indent  = 0
let g:pymode_doc     = 0
let g:pymode_rope    = 0

" PYMODE.Linting
let g:pymode_lint            = 1
let g:pymode_lint_write      = 1
let g:pymode_lint_unmodified = 0
let g:pymode_lint_checkers   = ['pep8']

" PYMODE.Syntax
let g:pymode_syntax = 1
let g:pymode_syntax_all = 1
let g:pymode_syntax_print_as_function = 1

Any help on this would be great. Thanks!

Error Screenshot

Upvotes: 1

Views: 1412

Answers (1)

phd
phd

Reputation: 94848

Coroutines (async def et al) were added in Python 3.5. If your python is less then 3.5 it surely doesn't recognize async def.

Test with

python --version

Upvotes: 1

Related Questions