如何通过 pyproject.toml 为特定文件禁用 pylint 消息?

问题描述 投票:0回答:1

我在多个文件中遇到

too-many-instance-attributes
pylint 错误 我只想对一个文件禁用此消息
my_project/runner/runner.py
。 可以在诗歌
pyproject.toml
文件中做到这一点吗?

pylint my_project

************* Module my_project.models_vi.config.hostname
my_project\models_vi\config\hostname.py:67:0: R0902: Too many instance attributes (9/7) (too-many-instance-attributes)
************* Module my_project.models_vi.config.port_descr
my_project\models_vi\config\port_descr.py:92:0: R0902: Too many instance attributes (11/7) (too-many-instance-attributes)
************* Module my_project.runner.runner
my_project\runner\runner.py:22:0: R0902: Too many instance attributes (9/7) (too-many-instance-attributes)
python pylint pyproject.toml
1个回答
0
投票

每个文件忽略插件,您可以使用以下方式忽略文件:

# Example from the plugin repository.

[tool.pylint.'MESSAGES CONTROL']
per-file-ignores = [
    "/folder_1/:missing-function-docstring,W0621,W0240,C0115",
    "file.py:C0116,E0001"
]

或者,如果您不想或不能使用插件,您可以在模块的开头添加注释,就像这样。

# runner.py
# pylint: disable=R0902
© www.soinside.com 2019 - 2024. All rights reserved.