假设我有代码
def foo():
bar = 1
wibble = 3
return locals()
我当前的语法检查器(带有 syntastic.vim 的 flake8)将在两个变量上抛出“分配给但从未使用”错误。然而 locals() 暗示了一些事情,如果不是明确的,它们实际上正在被使用。
def foo():
bar = 1
wibble = 3 # <-- I still want this to throw as it is definitely not being used
return bar
是否有任何 python 检查器或自定义设置将是 locals() 感知和宽松的?
编辑:
这是 vim/syntastic/flake8 的快速而肮脏的解决方案,它将抑制 .vimrc 中的警告
"Ignore unused variable warnings whenever locals() is being used in a file
function! LocalsWarningSuppress()
if ( search("locals()",'nw') > 0)
let g:syntastic_python_checker='flake8 --ignore=W806'
else
let g:syntastic_python_checker='flake8'
endif
endfunction
au BufWritePre **/(filter_pattern)*py call LocalsWarningSuppress()