使用Pylint显示错误和警告。

9

我开始使用Pylint,但由于我使用制表符而不是空格,因此它会给出警告。另外,由于一些方法来自基类,所以当实例'GalleryUi'没有'setModel'成员时,也会出现警告,尽管它的基类是QAbstractTableModel。那么我该如何设置Pylint才能不考虑这些问题...

No config file found, using default configuration
************* Module python.gallery
W:  7, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:  8, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 13, 0: Trailing whitespace (trailing-whitespace)
C: 15, 0: Trailing whitespace (trailing-whitespace)
W: 15, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 16, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 17, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 18, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 19, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 20, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 22, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 23, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 24, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 25, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 27, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 28, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 28, 0: Trailing whitespace (trailing-whitespace)
W: 31, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 32, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 33, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 34, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 36, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 37, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 39, 0: Trailing whitespace (trailing-whitespace)
W: 39, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 41, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 42, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 44, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 46, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 47, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 49, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 50, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 52, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 53, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 55, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 56, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 58, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 59, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 60, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 61, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 62, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 63, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 64, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 65, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 67, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 68, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 69, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 70, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 71, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 72, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 73, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 74, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 75, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 77, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 78, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 79, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 80, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 81, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 82, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 83, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 85, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 87, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 88, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 89, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 90, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 91, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 92, 0: Trailing whitespace (trailing-whitespace)
W: 92, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 95, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W: 96, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C: 99, 0: Line too long (88/80) (line-too-long)
W: 99, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:101, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:102, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:102, 0: Trailing whitespace (trailing-whitespace)
W:105, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:106, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:107, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:108, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:109, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:111, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:112, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:113, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:114, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:115, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:116, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:117, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:120, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:123, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:124, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:125, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:126, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:127, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:128, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:129, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:131, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:132, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:135, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:136, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:137, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:138, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:139, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:140, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:142, 0: Trailing whitespace (trailing-whitespace)
C:145, 0: Trailing whitespace (trailing-whitespace)
W:145, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:146, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:147, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:148, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:149, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:150, 0: Trailing whitespace (trailing-whitespace)
W:150, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:152, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:153, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:154, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:155, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:156, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:157, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:159, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:160, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:161, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:162, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:164, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:165, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:168, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:169, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:173, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:174, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:175, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:175, 0: Unnecessary semicolon (unnecessary-semicolon)
W:176, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:178, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:179, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:180, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:181, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:182, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:185, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:186, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:188, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:189, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:189, 0: Unnecessary semicolon (unnecessary-semicolon)
W:190, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:191, 0: Trailing whitespace (trailing-whitespace)
W:191, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:193, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:195, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:196, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:199, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:200, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:201, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:202, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:203, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:204, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:205, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:206, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:209, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:211, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:212, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:213, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:214, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:215, 0: Trailing whitespace (trailing-whitespace)
W:217, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:218, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:219, 0: Found indentation with tabs instead of spaces (mixed-indentation)
W:220, 0: Found indentation with tabs instead of spaces (mixed-indentation)
C:  1, 0: Missing module docstring (missing-docstring)
W:  3, 0: Relative import 'utils', should be 'python.utils' (relative-import)
F:  4, 0: Unable to import 'PyQt4' (import-error)
C: 17, 2: Invalid attribute name "_thumbRes" (invalid-name)
C: 16, 2: Invalid attribute name "_slideShowWin" (invalid-name)
C:  6, 0: Missing class docstring (missing-docstring)
R:  7, 1: Too many arguments (6/5) (too-many-arguments)
C:  7, 1: Invalid argument name "thumbRes" (invalid-name)
C: 22, 1: Invalid method name "colData" (invalid-name)
C: 22, 1: Missing method docstring (missing-docstring)
W: 22,19: Unused argument 'section' (unused-argument)
W: 22,28: Unused argument 'orientation' (unused-argument)
R: 22, 1: Method could be a function (no-self-use)
C: 27, 1: Invalid method name "headerData" (invalid-name)
W: 27,22: Unused argument 'section' (unused-argument)
R: 27, 1: Method could be a function (no-self-use)
C: 36, 1: Invalid method name "rowCount" (invalid-name)
W: 36,20: Unused argument 'parent' (unused-argument)
C: 41, 1: Invalid method name "columnCount" (invalid-name)
W: 41,23: Unused argument 'parent' (unused-argument)
C: 62, 4: Invalid variable name "fileName" (invalid-name)
C: 71, 4: Invalid variable name "fileName" (invalid-name)
C: 74, 3: Invalid variable name "exifData" (invalid-name)
R: 46, 1: Too many return statements (9/6) (too-many-return-statements)
W: 95,17: Unused argument 'index' (unused-argument)
R: 95, 1: Method could be a function (no-self-use)
C:101, 1: Invalid method name "setData" (invalid-name)
C:109, 4: Invalid variable name "newName" (invalid-name)
W:113, 3: Access to a protected member _renameFile of a client class (protected-access)
E:115, 3: Instance of 'MyListModel' has no 'dataChanged' member (no-member)
R:119, 0: Too many instance attributes (8/7) (too-many-instance-attributes)
C:188, 2: Invalid attribute name "animGallery" (invalid-name)
C:128, 2: Invalid attribute name "__animRate" (invalid-name)
C:146, 2: Invalid attribute name "_twoDLst" (invalid-name)
C:125, 2: Invalid attribute name "_slideShowWin" (invalid-name)
E:123, 1: Use of super on an old style class (super-on-old-class)
C:123, 1: Invalid argument name "imgagesPathLst" (invalid-name)
C:131, 1: Invalid method name "setUpWindow" (invalid-name)
W:136,10: Access to a protected member _browseDir of a client class (protected-access)
E:140, 2: Instance of 'GalleryUi' has no 'setWindowFlags' member (no-member)
E:147, 2: Instance of 'GalleryUi' has no 'setGeometry' member (no-member)
E:148, 2: Instance of 'GalleryUi' has no 'showFullScreen' member (no-member)
E:149, 2: Instance of 'GalleryUi' has no 'setColumnWidth' member (no-member)
E:152, 2: Instance of 'GalleryUi' has no 'setShowGrid' member (no-member)
E:153, 2: Instance of 'GalleryUi' has no 'setWordWrap' member (no-member)
E:154, 2: Instance of 'GalleryUi' has no 'setModel' member (no-member)
E:155, 2: Instance of 'GalleryUi' has no 'resizeColumnsToContents' member (no-member)
E:156, 2: Instance of 'GalleryUi' has no 'resizeRowsToContents' member (no-member)
E:157, 2: Instance of 'GalleryUi' has no 'selectionModel' member (no-member)
C:159, 1: Invalid method name "selChanged" (invalid-name)
C:159, 1: Missing method docstring (missing-docstring)
E:161, 9: Instance of 'GalleryUi' has no 'selectionModel' member (no-member)
E:162,12: Instance of 'GalleryUi' has no 'selectionModel' member (no-member)
C:168, 1: Invalid method name "animateUpSlideShow" (invalid-name)
C:185, 1: Invalid method name "animateUpGallery" (invalid-name)
C:195, 1: Invalid method name "keyPressEvent" (invalid-name)
E:203, 3: Instance of 'GalleryUi' has no 'close' member (no-member)
W:174, 2: Attribute 'animation' defined outside __init__ (attribute-defined-outside-init)
W:188, 2: Attribute 'animGallery' defined outside __init__ (attribute-defined-outside-init)
W:146, 2: Attribute '_twoDLst' defined outside __init__ (attribute-defined-outside-init)
W:150, 2: Attribute '_lm' defined outside __init__ (attribute-defined-outside-init)
C:208, 0: Invalid argument name "imgLst" (invalid-name)
E:213, 1: Instance of 'GalleryUi' has no 'raise_' member (no-member)
C:217, 1: Invalid constant name "current_path" (invalid-name)
C:219, 2: Invalid constant name "current_path" (invalid-name)
3个回答

29
你可以使用一个~/.pylintrc文件来配置Pylint。其中之一的功能是允许你忽略你不关心的警告。如果你必须使用制表符,请通过将indent-string选项设置为制表符来告诉Pylint:
[FORMAT]
indent-string=\t

Pylint仅会在您的代码中混用制表符和空格时发出警告-这是您绝对不应该做的,并且需要在代码中注意此问题。
要禁用其他警告,请使用Message Control逐个关闭它们:
[MESSAGES CONTROL]
# C0111: Missing docstring
# R0904: Too many public methods
disable=C0111,R0904

要获取您感兴趣的消息的ID,请查看Pylint报告中的“MESSAGES”部分,或参见http://pylint-messages.wikidot.com/all-codes

还请参阅Pylint文档中的Message Control部分,以及有关如何找到与特定命令行选项对应的.pylintrc选项名称的FAQ条目

我真的建议使用.pylintrc,但为了完整起见,您的其他选择是:

  • 使用提示性注释为Pylint注释您的源代码,例如#pylint: disable=W0123,E4567
  • 使用相应的命令行选项调用pylint,例如pylint --disable=W0702,C0103

我该如何理解消息 ID? - Ciasto piekarz
@san,请看我的编辑。最简单的方法是在http://pylint-messages.wikidot.com/all-codes上查找。 - Lukas Graf
顺便说一下,我在我的OSx用户目录中保存了一个.pylintrc文件,但我仍然收到我设置为忽略的消息。 - Ciasto piekarz
@san 如果你需要的话,我可以在聊天室里尝试帮助你。 - Lukas Graf
获取PyQt4导入错误,访问客户端类的受保护成员_renameFile是否有误? - Ciasto piekarz
2
请注意,pylint 1.0 推荐使用符号名称而不是数字 ID。它们更易于阅读和记忆。要从数字 ID 获取符号名称,请尝试 pylint --help-msg C0111。要获取完整的消息列表,请尝试 pylint --list-msg - sthenault

1
在SublimeLinter中,如果有选项卡错误,请添加以下内容:

"pep8_ignore":
[
    "W191"
]

收件人:

[Sublime数据文件夹]\Packages\User\SublimeLinter.sublime-settings

额外奖励,添加:

"pep8": false

忽略其他的Pep8错误,比如行长度,可以将其添加到同一个文件中。
从主菜单选择“首选项”>“浏览程序包”来打开正确的文件夹。

1
PEP8的理念是使用4个空格进行缩进。
您可以告诉您的代码编辑器或IDE将制表符转换为空格块。
例如,在Sublime 3上:
-检查底部状态栏,单击“Spaces” -弹出菜单,单击“Convert Indentation to Spaces”

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接