PyCharm选择性忽略PEP8代码风格警告信息

Posted zgljl2012

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PyCharm选择性忽略PEP8代码风格警告信息相关的知识,希望对你有一定的参考价值。

用了几天的PyCharm,发现确实在编写Python代码上非常好用,但有一点体验不太好,就是代码编写时要按照PEP8代码风格编写,不然会有波浪线的警告信息。解决方法如下:

方法一:

将鼠标移到提示的地方,按alt+Enter,选择忽略(Ignore)这个错误即好。

方法二

打开:File - Settings…… - Editor - Inspections

在python下找到 PEP8 coding style violation,在右边下面的Ignore errors里可以添加忽略的警告信息ID,如下:

如E302就是忽略“expected 2 blank lines, found 0”这个警告(出现在我想给方法上面添加注释的时候)。


警告信息对应的ID在http://pep8.readthedocs.io/en/latest/intro.html#configuration中可找到。

原文地址


附录如下:

codesample message
E1Indentation
E101indentation contains mixed spaces and tabs
E111indentation is not a multiple of four
E112expected an indented block
E113unexpected indentation
E114indentation is not a multiple of four (comment)
E115expected an indented block (comment)
E116unexpected indentation (comment)
E121 (*^)continuation line under-indented for hanging indent
E122 (^)continuation line missing indentation or outdented
E123 (*)closing bracket does not match indentation of opening bracket’s line
E124 (^)closing bracket does not match visual indentation
E125 (^)continuation line with same indent as next logical line
E126 (*^)continuation line over-indented for hanging indent
E127 (^)continuation line over-indented for visual indent
E128 (^)continuation line under-indented for visual indent
E129 (^)visually indented line with same indent as next logical line
E131 (^)continuation line unaligned for hanging indent
E133 (*)closing bracket is missing indentation
E2Whitespace
E201whitespace after ‘(‘
E202whitespace before ‘)’
E203whitespace before ‘:’
E211whitespace before ‘(‘
E221multiple spaces before operator
E222multiple spaces after operator
E223tab before operator
E224tab after operator
E225missing whitespace around operator
E226 (*)missing whitespace around arithmetic operator
E227missing whitespace around bitwise or shift operator
E228missing whitespace around modulo operator
E231missing whitespace after ‘,’, ‘;’, or ‘:’
E241 (*)multiple spaces after ‘,’
E242 (*)tab after ‘,’
E251unexpected spaces around keyword / parameter equals
E261at least two spaces before inline comment
E262inline comment should start with ‘# ‘
E265block comment should start with ‘# ‘
E266too many leading ‘#’ for block comment
E271multiple spaces after keyword
E272multiple spaces before keyword
E273tab after keyword
E274tab before keyword
E275missing whitespace after keyword
E3Blank line
E301expected 1 blank line, found 0
E302expected 2 blank lines, found 0
E303too many blank lines (3)
E304blank lines found after function decorator
E305expected 2 blank lines after end of function or class
E4Import
E401multiple imports on one line
E402module level import not at top of file
E5Line length
E501 (^)line too long (82 > 79 characters)
E502the backslash is redundant between brackets
E7Statement
E701multiple statements on one line (colon)
E702multiple statements on one line (semicolon)
E703statement ends with a semicolon
E704 (*)multiple statements on one line (def)
E711 (^)comparison to None should be ‘if cond is None:’
E712 (^)comparison to True should be ‘if cond is True:’ or ‘if cond:’
E713test for membership should be ‘not in’
E714test for object identity should be ‘is not’
E721 (^)do not compare types, use ‘isinstance()’
E731do not assign a lambda expression, use a def
E741do not use variables named ‘l’, ‘O’, or ‘I’
E742do not define classes named ‘l’, ‘O’, or ‘I’
E743do not define functions named ‘l’, ‘O’, or ‘I’
E9Runtime
E901SyntaxError or IndentationError
E902IOError
W1Indentation warning
W191indentation contains tabs
W2Whitespace warning
W291trailing whitespace
W292no newline at end of file
W293blank line contains whitespace
W3Blank line warning
W391blank line at end of file
W5Line break warning
W503 (*)line break occurred before a binary operator
W6Deprecation warning
W601.has_key() is deprecated, use ‘in’
W602deprecated form of raising exception
W603‘<>’ is deprecated, use ‘!=’
W604backticks are deprecated, use ‘repr()’

以上是关于PyCharm选择性忽略PEP8代码风格警告信息的主要内容,如果未能解决你的问题,请参考以下文章

PyCharm选择性忽略PEP8代码风格警告信息

pycharm unused import statement 是啥原因?

Pycharm之关闭拼写检查警告

pycharm中配置pep8

Pycharm配置autopep8教程,让Python代码更符合pep8规范

pycharm配置pep8