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

Pylint的--fail-under参数无法正常工作问题求助

Troubleshooting Pylint's --fail-under Parameter Not Working

Your Environment & Configuration

First, let's recap your setup to make sure we're aligned:

  • Pylint version: pylint 2.8.2
  • astroid version: 2.5.6
  • Python version: 3.6.1
  • Run command: pylint package --fail-under=8 --rcfile=pylintrc

Your pylintrc configuration:

[BASIC]
# 始终允许的良好变量名,以逗号分隔
good-names=i,j,k,e,_
# 私有条目无需文档说明
# 注意,私有条目需以单下划线而非双下划线标记
no-docstring-rgx=_.*
[FORMAT]
# 遵循通用规范
max-line-length=79
[MESSAGES CONTROL]
# I0011 - 本地禁用...
# 若Pylint消息被本地禁用,必然存在相应原因,无需显示警告
# C0203 - 元类方法...应将'cls'作为第一个参数
# pep8规范与此不同,我们遵循pep8
# R1705 - no-else-return:"return"后不必要的"else"
# 有时结尾的else看起来更清晰,我们允许这种写法
disable=I0011, C0203, R1705
[REPORTS]
# 设置输出格式,可选格式包括text、parseable、colorized和html
output-format=text
# 合理的消息模板
msg-template=@{line}: [{msg_id} {symbol}] {msg}
[MASTER]
# 由于numpy是C扩展,必须加入白名单
# MySQLdb异常同理
extension-pkg-whitelist=numpy,MySQLdb
[TYPECHECK]
# numpy包含大量Pylint无法识别的动态生成字段
# 需要忽略这些字段
ignored-modules = numpy
ignored-classes = numpy
[SIMILARITIES]
# 忽略相似导入,参考:
# https://stackoverflow.com/questions/29206482/pylint-duplicate-code-false-positive
# 相较于禁用整个文件的相似性检查,仅禁用导入部分的检查更合理
# 因为导入是必需的
ignore-imports=yes

Troubleshooting Steps & Fixes

I’ve run into similar quirks with --fail-under before, so here are practical directions to diagnose and fix the issue:

  • Verify the actual calculated score
    The --fail-under flag checks against the average overall project score, not individual module scores. First, run Pylint without the --fail-under parameter and look for the final line: Your code has been rated at X/10. If this X is 8 or higher, that’s why the command isn’t failing. Also, double-check that all target files are being analyzed (none are ignored via your rcfile or implicit Pylint rules).

  • Check for version-specific bugs
    While --fail-under exists in Pylint 2.0+, older versions like 2.8.x have known quirks with this parameter. Try upgrading to a newer stable version compatible with Python 3.6 (e.g., 2.14.x is the last major release supporting 3.6) with:

    pip install --upgrade pylint astroid
    

    Re-test the command after upgrading to see if the parameter starts working.

  • Isolate the rcfile’s impact
    Your rcfile might be indirectly affecting the score or parameter behavior. Try running Pylint without the rcfile:

    pylint package --fail-under=8
    

    If the parameter works here, dig into your rcfile settings—specifically the disable list. Disabling multiple checks could mask issues that would lower your score, keeping it above 8. Try temporarily commenting out the disable line to see if the score drops and the failure triggers.

  • Validate parameter syntax
    Some Pylint versions are picky about parameter formatting. Try using a space instead of an equals sign:

    pylint package --fail-under 8 --rcfile=pylintrc
    

    Also, confirm that package is the correct path—if it’s empty or inaccessible, Pylint might return a perfect score without analyzing any code.

  • Enable verbose logging
    Run Pylint with the -v flag to get detailed logs about parameter loading and score calculation:

    pylint -v package --fail-under=8 --rcfile=pylintrc
    

    Look for lines confirming that fail-under=8 is being applied, and check for odd behavior in how scores are computed for your files.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 16:27:36