You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

引入flake8-import-restrictions插件后I2041错误码无法忽略的问题求助

解决flake8-import-restrictions插件I2041错误码无法忽略的问题

问题原因

Flake8 默认会验证错误码是否符合 ^[A-Z]{1,3}[0-9]{0,3}$ 的格式(1-3个大写字母 + 0-3个数字),而插件抛出的 I2041 包含4个数字,不符合这个格式,因此被Flake8的配置解析器拒绝。

解决方案

在setup.cfg的[flake8]段落中添加strict-error-codes = False,关闭错误码的严格格式验证,这样就能正常忽略I2041:

[flake8]
ignore = D413, E203, E266, E501, E711, F401, F403, I2041, W503
max-line-length = 100
max-complexity = 18
application-import-names = myproject,tests
import-order-style = google
exclude = tests/integration/.env.shadow, env
strict-error-codes = False

注意事项

  • 确保你的Flake8版本不低于3.8.0,因为strict-error-codes选项是从这个版本开始引入的。如果版本过低,需要先执行升级:
    pip install --upgrade flake8
    

内容的提问来源于stack exchange,提问作者Khalil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 02:48:31