升级Flake8至v6.0.0后运行报错ValueError: 'choice' is not callable
Flake8 v6.0.0执行
flake8报错ValueError: 'choice' is not callable的解决方法 问题根源
从报错栈能直接定位,错误来自flake8-quotes插件的参数注册逻辑。Flake8 v6.0.0重构了选项解析模块,用argparse替代了旧版的optparse,而旧版本的flake8-quotes在注册--quotes选项时,错误使用了choice参数(argparse规范参数名是choices),导致解析器识别失败,抛出ValueError: 'choice' is not callable。
解决步骤
升级
flake8-quotes到兼容版本
执行命令更新插件:pip install --upgrade flake8-quotes需确保安装的版本≥3.3.0,该版本修复了与Flake8 v6的兼容问题。
验证修复效果
重新在项目根目录执行flake8命令,确认报错消失。
补充说明
你之前尝试的降级Flake8到5.0.4虽然能临时解决问题,但升级flake8-quotes插件可以保留Flake8 v6的新特性,是更合理的解决方案。
环境信息
- Python版本:3.8.15(使用虚拟环境
env) - 报错时Flake8版本:v6.0.0
- 项目
setup.cfg配置:
# Black-compatible configurations [isort] multi_line_output = 3 include_trailing_comma = True force_grid_wrap = 0 use_parentheses = True ensure_newline_before_comments = True line_length = 88 [flake8] ignore = D413, E203, E266, E501, E711, W503, F401, F403 max-line-length = 100 max-complexity = 18 select = B,C,E,F,W,T4,B9 application-import-names = myproject,tests import-order-style = google per-file-ignores = __init__.py:F401 exclude = tests/integration/.env.shadow, env require-plugins = flake8-import-single [pylint] max-line-length = 88 [pylint.messages_control] disable = C0330, C0326
内容的提问来源于stack exchange,提问作者Khalil
相关产品推荐
相关产品推荐

