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

VS Code中Pylint配置禁用规则无效,报错问题求助

解决Pylint的C0114和C0209报错问题

方式一:修改VS Code配置禁用指定规则

当前你的settings.json仅禁用了部分Pylint规则,未覆盖C0114(模块缺少文档字符串)和C0209(建议使用f-string)。直接在配置中添加禁用这两个规则的参数即可:

"python.linting.enabled": true,
"python.linting.pylintArgs": [
    "--disable=line-too-long",
    "--disable=unused-argument",
    "--disable=C0111",
    "--disable=C0114",
    "--disable=C0209",
    "--errors-only"
],

保存配置后重启VS Code,报错会消失。

方式二:修复代码符合Pylint规范

如果不想禁用规则,可直接修改代码满足检查要求:

  1. 添加模块文档字符串(解决C0114)
    在代码最顶部添加模块级说明:
"""定义椅子组件及整体类的模块"""
  1. 替换format为f-string(解决C0209)
    修改Chair类的__repr__方法:
def __repr__(self):
    return f"I have {len(self.legs)} and one back"

另外注意:原代码中self.legs = [leg() for leg in range(num_legs)]存在语法错误,leg是循环变量而非Leg类,会触发NameError,需修正为:

self.legs = [Leg() for _ in range(num_legs)]

修复后的完整代码:

"""定义椅子组件及整体类的模块"""

class Leg:
    pass


class Back:
    pass


class Chair:
    def __init__(self, num_legs):
        self.legs = [Leg() for _ in range(num_legs)]
        self.back = Back()

    def __repr__(self):
        return f"I have {len(self.legs)} and one back"


print(Chair(5))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 21:20:37