【问题标题】:Vim pymode throws "invalid syntax" error on async function definitionVim pymode 在异步函数定义中抛出“无效语法”错误
【发布时间】:2018-01-01 04:28:20
【问题描述】:

我目前正在 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

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

【问题讨论】:

    标签: python vim python-mode


    【解决方案1】:

    在 Python 3.5 中添加了协程(async def 等)。如果您的 python 小于 3.5,它肯定无法识别 async def

    测试

    python --version
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-18
      • 2021-12-14
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多