gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 14:19:13 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com