Vim pymode在异步函数定义上抛出“无效语法”错误

时间:2018-01-01 04:28:21

标签: python vim python-mode

我目前正在vim中开发一些异步python并安装pymode作为插件。但是我遇到了文件linting的问题,因为linter挂起了第一个(和有效的)async定义,并且不会丢失文件的其余部分。

@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

我的vimrc的语言设置为python3,语法检查器设置为pep8,但这似乎无法解决错误。

" ~/.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

对此的任何帮助都会很棒。谢谢!

Error Screenshot

1 个答案:

答案 0 :(得分:1)

在Python 3.5中添加了Coroutines(async def等)。如果你的python小于3.5,它肯定不会识别async def

使用

进行测试
python --version