python - Vim pymode 在异步函数定义上抛出 "invalid syntax"错误

标签 python vim python-mode

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

@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

最佳答案

协程(async def 等)是在 Python 3.5 中添加的。如果你的Python版本低于3.5,它肯定无法识别async def

测试

python --version

关于python - Vim pymode 在异步函数定义上抛出 "invalid syntax"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48047134/

相关文章:

haskell - 如何让 vim-haskellmode 和 cabal-dev 一起工作?

vim - (vim 分析)VIM 256 色模式,滞后的 php 文件

python:显示帮助文档

python - 有没有更聪明的方法来获取用切片对象切片的列表的索引?

python - 如何让 python 进程保持事件状态——正确的方法

python - 使用元组作为 lambda 的参数会引发有关缺少所需位置参数的错误

包含 `r` 的 Vim 命令导致我替换

python - 如何解析 json 数据 python django?

linux - 使用 BASH 脚本组合两行

emacs - 在emacs 23中将python缩进设置为2个空格?