Flakehell忽略darglint的setup.cfg参数问题及配置方法咨询
解决Flakehell不识别darglint文档字符串样式配置的问题
我来帮你搞定这个问题!你遇到的核心原因是Flakehell作为flake8的封装工具,对插件配置的传递逻辑和直接运行darglint不一样——它不会自动读取setup.cfg里的[darglint]独立配置段,也不会把pyproject.toml中[tool.flakehell]下的自定义配置传递给darglint插件。下面给你两种可行的解决方案:
方案一:直接在Flakehell插件配置中传递darglint参数
修改你的pyproject.toml,在[tool.flakehell.plugins]下给flake8-darglint添加--docstring-style参数:
[tool.flakehell] [tool.flakehell.plugins] flake8-darglint = [ "+*", "--docstring-style=numpy" ]
这种方式最直接,Flakehell会把指定的参数直接传递给对应的flake8插件(也就是darglint),确保它能识别到numpy风格的配置。
方案二:将darglint配置放到flake8的通用配置段
darglint作为flake8插件,会读取flake8核心配置中的docstring_style参数。你可以把配置写到flake8的配置区域:
如果你用pyproject.toml:
[tool.flake8] docstring_style = "numpy" [tool.flakehell] [tool.flakehell.plugins] flake8-darglint = ["+*"]
如果你用setup.cfg:
[flake8] docstring_style = numpy [darglint] # 这里的配置可以保留,但Flakehell主要读取[flake8]段的参数 docstring_style = numpy
Flakehell会加载flake8的核心配置,这样darglint就能间接获取到样式设置了。
为什么之前的配置不生效?
pyproject.toml中[tool.flakehell]下的docstring_style是无效的:Flakehell本身没有这个配置项,它不会把这个自定义字段传递给darglint插件。setup.cfg中的[darglint]段:Flakehell的配置加载逻辑优先处理自身和flake8的核心配置,对于插件独立的配置段(比如[darglint]),可能不会主动读取并传递给插件,这就导致直接运行darglint能识别,但通过Flakehell运行时不行。
修改完成后,重新运行flakehell lint就能正常识别numpy风格的文档字符串了!
内容的提问来源于stack exchange,提问作者Henhuy
相关产品推荐
相关产品推荐

