是否可以在不更改源代码的情况下使用 pylint 忽略一个特定的行?

Is it possible to ignore one single specific line with pylint, without changes to the source code?

的解决方案需要在源代码中乱加注释,这对我来说是不受欢迎的。

有没有办法在 pylint 命令行工具的参数中指定给定实例是误报?

我认为在不更改源代码的情况下不可能忽略特定行。但是,当然可以忽略 .pylintrc 或文件顶部的警告类型。

我会采用创建 .pylintrc 的方法来满足您的需要。例如,如果您想完全忽略 W0612: unused-variable,那么您可以 create a .pylintrc file and add message names to disable as noted in pytest docs

.pylintrc

disable=unused-variable,
..., 

或者,您可以根据具体情况禁用消息 at the top of the file,然后告诉您的学生忽略它:

文件顶部

# pylint: disable=unused-variable, wildcard-import, method-hidden
# pylint: enable=too-many-lines